github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/nomad/drainer/drainer_util_test.go (about) 1 package drainer 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/nomad/nomad/structs" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestDrainer_PartitionAllocDrain(t *testing.T) { 11 t.Parallel() 12 // Set the max ids per reap to something lower. 13 maxIdsPerTxn := 2 14 15 require := require.New(t) 16 transitions := map[string]*structs.DesiredTransition{"a": nil, "b": nil, "c": nil} 17 evals := []*structs.Evaluation{nil, nil, nil} 18 requests := partitionAllocDrain(maxIdsPerTxn, transitions, evals) 19 require.Len(requests, 3) 20 21 first := requests[0] 22 require.Len(first.Transitions, 2) 23 require.Len(first.Evals, 0) 24 25 second := requests[1] 26 require.Len(second.Transitions, 1) 27 require.Len(second.Evals, 1) 28 29 third := requests[2] 30 require.Len(third.Transitions, 0) 31 require.Len(third.Evals, 2) 32 } 33 34 func TestDrainer_PartitionIds(t *testing.T) { 35 t.Parallel() 36 require := require.New(t) 37 38 // Set the max ids per reap to something lower. 39 maxIdsPerTxn := 2 40 41 ids := []string{"1", "2", "3", "4", "5"} 42 requests := partitionIds(maxIdsPerTxn, ids) 43 require.Len(requests, 3) 44 require.Len(requests[0], 2) 45 require.Len(requests[1], 2) 46 require.Len(requests[2], 1) 47 require.Equal(requests[0][0], ids[0]) 48 require.Equal(requests[0][1], ids[1]) 49 require.Equal(requests[1][0], ids[2]) 50 require.Equal(requests[1][1], ids[3]) 51 require.Equal(requests[2][0], ids[4]) 52 }