Skip to content

Commit

Permalink
fix: add test for picking a random pod within an ownerref group
Browse files Browse the repository at this point in the history
  • Loading branch information
linki committed May 2, 2020
1 parent 089bb2c commit d7758b6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions chaoskube/chaoskube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,32 +949,47 @@ func (suite *Suite) TestFilterByOwnerReference() {
baz1 := util.NewPod("default", "baz-1", v1.PodRunning)

for _, tt := range []struct {
seed int64
name string
pods []v1.Pod
expected []v1.Pod
}{
{
name: "2 pods, same parent",
seed: 1000,
name: "2 pods, same parent, pick first",
pods: []v1.Pod{foo, foo1},
expected: []v1.Pod{foo},
},
{
seed: 2000,
name: "2 pods, same parent, pick second",
pods: []v1.Pod{foo, foo1},
expected: []v1.Pod{foo1},
},
{
seed: 1000,
name: "2 pods, different parents",
pods: []v1.Pod{foo, bar},
expected: []v1.Pod{foo, bar},
},
{
seed: 1000,
name: "2 pods, one with/without parent",
pods: []v1.Pod{foo, baz},
expected: []v1.Pod{foo, baz},
expected: []v1.Pod{baz, foo}, // implementation detail: pods without owner reference appear first in the list
},
{
seed: 1000,
name: "2 pods, no parents",
pods: []v1.Pod{baz, baz1},
expected: []v1.Pod{baz, baz1},
},
} {
rand.Seed(tt.seed)

results := filterByOwnerReference(tt.pods)
suite.Require().Len(results, len(tt.expected))

for i, result := range results {
suite.Assert().Equal(tt.expected[i], result, tt.name)
}
Expand Down

0 comments on commit d7758b6

Please # to comment.