From 4e5f9d3f64455f06c7aaf4ac65b711d6f266ca61 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Tue, 4 Aug 2015 18:32:50 -0700 Subject: [PATCH] nomad: test AllocsByNode --- nomad/state_store_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/nomad/state_store_test.go b/nomad/state_store_test.go index e43e7ecb2..9d382de8e 100644 --- a/nomad/state_store_test.go +++ b/nomad/state_store_test.go @@ -785,6 +785,34 @@ func TestStateStore_EvictAlloc_GetAlloc(t *testing.T) { } } +func TestStateStore_AllocsByNode(t *testing.T) { + state := testStateStore(t) + var allocs []*structs.Allocation + + for i := 0; i < 10; i++ { + alloc := mockAlloc() + alloc.NodeID = "foo" + allocs = append(allocs, alloc) + } + + err := state.UpdateAllocations(1000, nil, allocs) + if err != nil { + t.Fatalf("err: %v", err) + } + + out, err := state.AllocsByNode("foo") + if err != nil { + t.Fatalf("err: %v", err) + } + + sort.Sort(AllocIDSort(allocs)) + sort.Sort(AllocIDSort(out)) + + if !reflect.DeepEqual(allocs, out) { + t.Fatalf("bad: %#v %#v", allocs, out) + } +} + func TestStateStore_Allocs(t *testing.T) { state := testStateStore(t) var allocs []*structs.Allocation