2015-09-08 22:37:07 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-09-09 00:49:31 +00:00
|
|
|
func TestAllocations_List(t *testing.T) {
|
2015-09-08 22:37:07 +00:00
|
|
|
c, s := makeClient(t, nil, nil)
|
|
|
|
defer s.Stop()
|
2015-09-09 00:49:31 +00:00
|
|
|
a := c.Allocations()
|
2015-09-08 22:37:07 +00:00
|
|
|
|
|
|
|
// Querying when no allocs exist returns nothing
|
2015-09-09 20:18:50 +00:00
|
|
|
allocs, qm, err := a.List(nil)
|
2015-09-08 22:37:07 +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 22:37:07 +00:00
|
|
|
if n := len(allocs); n != 0 {
|
|
|
|
t.Fatalf("expected 0 allocs, got: %d", n)
|
|
|
|
}
|
2015-09-09 00:20:52 +00:00
|
|
|
|
|
|
|
// TODO: do something that causes an allocation to actually happen
|
|
|
|
// so we can query for them.
|
|
|
|
return
|
|
|
|
|
|
|
|
job := &Job{
|
|
|
|
ID: "job1",
|
|
|
|
Name: "Job #1",
|
2015-09-10 00:29:43 +00:00
|
|
|
Type: JobTypeService,
|
2015-09-09 00:20:52 +00:00
|
|
|
}
|
|
|
|
eval, _, err := c.Jobs().Register(job, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// List the allocations again
|
2015-09-09 20:18:50 +00:00
|
|
|
allocs, qm, err = a.List(nil)
|
2015-09-09 00:20:52 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if qm.LastIndex == 0 {
|
|
|
|
t.Fatalf("bad index: %d", qm.LastIndex)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that we got the allocation back
|
|
|
|
if len(allocs) == 0 || allocs[0].EvalID != eval {
|
|
|
|
t.Fatalf("bad: %#v", allocs)
|
|
|
|
}
|
2015-09-08 22:37:07 +00:00
|
|
|
}
|