Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 12e64a9

Browse files
author
James Munnelly
committed
Add test names to TestDeterminePilotsToBeRemoved
1 parent ea88b71 commit 12e64a9

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

pkg/controllers/elasticsearch/actions/scale_test.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -344,49 +344,42 @@ func TestDeterminePilotsToBeRemoved(t *testing.T) {
344344
expectedOutput []*v1alpha1.Pilot
345345
err bool
346346
}
347-
tests := []testT{
348-
{
347+
tests := map[string]testT{
348+
"should only remove highest ordinal pilot in 'test' set": {
349349
inputList: []*v1alpha1.Pilot{pilotWithName("es-test-0"), pilotWithName("es-test-1"), pilotWithName("es-test-2")},
350350
statefulSet: generate.StatefulSet(generate.StatefulSetConfig{Name: "es-test", Replicas: int32Ptr(3)}),
351351
replicaDiff: -1,
352352
expectedOutput: []*v1alpha1.Pilot{pilotWithName("es-test-2")},
353353
err: false,
354354
},
355-
{
355+
"should not remove pilot that is not a member of the specified statefulset": {
356356
inputList: []*v1alpha1.Pilot{pilotWithName("es-test-0"), pilotWithName("es-mixed-1"), pilotWithName("es-test-1")},
357357
statefulSet: generate.StatefulSet(generate.StatefulSetConfig{Name: "es-test", Replicas: int32Ptr(2)}),
358358
replicaDiff: -1,
359359
expectedOutput: []*v1alpha1.Pilot{pilotWithName("es-test-1")},
360360
err: false,
361361
},
362-
{
362+
"should not remove any pilots if replicaDiff is 0 and highest ordinal pilot is missing": {
363363
inputList: []*v1alpha1.Pilot{pilotWithName("es-test-0")},
364364
statefulSet: generate.StatefulSet(generate.StatefulSetConfig{Name: "es-test", Replicas: int32Ptr(2)}),
365365
replicaDiff: 0,
366366
err: false,
367367
},
368-
{
368+
"should not remove any pilots if replica diff is 0": {
369369
inputList: []*v1alpha1.Pilot{pilotWithName("es-test-0")},
370370
statefulSet: generate.StatefulSet(generate.StatefulSetConfig{Name: "es-test", Replicas: int32Ptr(1)}),
371371
replicaDiff: 0,
372372
err: false,
373373
},
374-
{
375-
inputList: []*v1alpha1.Pilot{pilotWithName("es-test-0"), pilotWithName("es-test-1")},
376-
statefulSet: generate.StatefulSet(generate.StatefulSetConfig{Name: "es-test", Replicas: int32Ptr(2)}),
377-
replicaDiff: -1,
378-
expectedOutput: []*v1alpha1.Pilot{pilotWithName("es-test-1")},
379-
err: false,
380-
},
381-
{
374+
"should not remove any pilots of replicaDiff is positive": {
382375
inputList: []*v1alpha1.Pilot{pilotWithName("es-test-0"), pilotWithName("es-test-1")},
383376
statefulSet: generate.StatefulSet(generate.StatefulSetConfig{Name: "es-test", Replicas: int32Ptr(2)}),
384377
replicaDiff: 1,
385378
err: false,
386379
},
387380
}
388-
for i, test := range tests {
389-
t.Run(fmt.Sprintf("test-%d", i), func(t *testing.T) {
381+
for name, test := range tests {
382+
t.Run(name, func(t *testing.T) {
390383
output, err := determinePilotsToBeRemoved(test.inputList, test.statefulSet, test.replicaDiff)
391384
if err != nil && !test.err {
392385
t.Errorf("Expected no error but got: %v", err)

0 commit comments

Comments
 (0)