github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/strategy/drained_test.go (about) 1 package strategy 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestDrainedPlan(t *testing.T) { 11 nodes := []Info{ 12 { 13 Nodename: "n1", 14 Capacity: 10, 15 Count: 2, 16 }, 17 { 18 Nodename: "n2", 19 Capacity: 9, 20 Count: 3, 21 }, 22 { 23 Nodename: "n3", 24 Capacity: 10, 25 Count: 5, 26 }, 27 { 28 Nodename: "n4", 29 Capacity: 8, 30 Count: 7, 31 }, 32 } 33 34 r, err := DrainedPlan(context.Background(), nodes, 1, 100, 0) 35 assert.NoError(t, err) 36 assert.ElementsMatch(t, []int{2, 3, 5, 8}, getFinalStatus(r, nodes)) 37 38 r, err = DrainedPlan(context.Background(), nodes, 2, 1, 0) 39 assert.Error(t, err) 40 41 r, err = DrainedPlan(context.Background(), nodes, 2, 100, 0) 42 assert.NoError(t, err) 43 assert.ElementsMatch(t, []int{2, 3, 5, 9}, getFinalStatus(r, nodes)) 44 45 r, err = DrainedPlan(context.Background(), nodes, 3, 100, 0) 46 assert.ElementsMatch(t, []int{2, 3, 5, 10}, getFinalStatus(r, nodes)) 47 48 r, err = DrainedPlan(context.Background(), nodes, 10, 100, 0) 49 assert.NoError(t, err) 50 assert.ElementsMatch(t, []int{2, 5, 5, 15}, getFinalStatus(r, nodes)) 51 52 r, err = DrainedPlan(context.Background(), nodes, 25, 100, 0) 53 assert.NoError(t, err) 54 assert.ElementsMatch(t, []int{10, 12, 5, 15}, getFinalStatus(r, nodes)) 55 56 r, err = DrainedPlan(context.Background(), nodes, 29, 100, 0) 57 assert.NoError(t, err) 58 assert.ElementsMatch(t, []int{12, 12, 7, 15}, getFinalStatus(r, nodes)) 59 60 r, err = DrainedPlan(context.Background(), nodes, 37, 100, 0) 61 assert.NoError(t, err) 62 assert.ElementsMatch(t, []int{12, 12, 15, 15}, getFinalStatus(r, nodes)) 63 }