open-nomad/api/job_test.go

58 lines
1.1 KiB
Go
Raw Normal View History

2015-09-08 23:24:26 +00:00
package api
import (
"reflect"
"testing"
)
func TestJobs_Register(t *testing.T) {
c, s := makeClient(t, nil, nil)
defer s.Stop()
jobs := c.Jobs()
// Listing jobs before registering returns nothing
2015-09-08 23:45:16 +00:00
resp, qm, err := jobs.List()
2015-09-08 23:24:26 +00:00
if err != nil {
t.Fatalf("err: %s", err)
}
2015-09-08 23:45:16 +00:00
if qm.LastIndex != 0 {
t.Fatalf("bad index: %d", qm.LastIndex)
}
2015-09-08 23:24:26 +00:00
if n := len(resp); n != 0 {
t.Fatalf("expected 0 jobs, got: %d", n)
}
// Create a job and attempt to register it
job := &Job{
ID: "job1",
Name: "Job #1",
Type: "service",
Priority: 1,
}
2015-09-08 23:45:16 +00:00
eval, wm, err := jobs.Register(job, nil)
2015-09-08 23:24:26 +00:00
if err != nil {
t.Fatalf("err: %s", err)
}
if eval == "" {
t.Fatalf("missing eval id")
}
2015-09-08 23:45:16 +00:00
if wm.LastIndex == 0 {
t.Fatalf("bad index: %d", wm.LastIndex)
}
2015-09-08 23:24:26 +00:00
// Query the jobs back out again
2015-09-08 23:45:16 +00:00
resp, qm, err = jobs.List()
2015-09-08 23:24:26 +00:00
if err != nil {
t.Fatalf("err: %s", err)
}
2015-09-08 23:45:16 +00:00
if qm.LastIndex == 0 {
t.Fatalf("bad index: %d", qm.LastIndex)
}
2015-09-08 23:24:26 +00:00
// Check that we got the expected response
expect := []*Job{job}
if !reflect.DeepEqual(resp, expect) {
t.Fatalf("bad: %#v", resp[0])
}
}