|
38 | 38 | } |
39 | 39 | ) |
40 | 40 |
|
| 41 | +func Test_isPodUpdateNetPolRelevant(t *testing.T) { |
| 42 | + t.Run("Pod phase change should be detected as NetworkPolicy relevant", func(t *testing.T) { |
| 43 | + newPod := fakePod.DeepCopy() |
| 44 | + newPod.Status.Phase = api.PodFailed |
| 45 | + assert.True(t, isPodUpdateNetPolRelevant(&fakePod, newPod)) |
| 46 | + }) |
| 47 | + t.Run("Pod IP change should be detected as NetworkPolicy relevant", func(t *testing.T) { |
| 48 | + newPod := fakePod.DeepCopy() |
| 49 | + newPod.Status.PodIP = "172.16.0.2" |
| 50 | + assert.True(t, isPodUpdateNetPolRelevant(&fakePod, newPod)) |
| 51 | + }) |
| 52 | + t.Run("Pod IPs change should be detected as NetworkPolicy relevant", func(t *testing.T) { |
| 53 | + newPod := fakePod.DeepCopy() |
| 54 | + newPod.Status.PodIPs = []api.PodIP{{IP: "172.16.0.2"}} |
| 55 | + assert.True(t, isPodUpdateNetPolRelevant(&fakePod, newPod)) |
| 56 | + }) |
| 57 | + t.Run("Pod Label change should be detected as NetworkPolicy relevant", func(t *testing.T) { |
| 58 | + newPod := fakePod.DeepCopy() |
| 59 | + newPod.ObjectMeta.Labels = map[string]string{"bar": "foo"} |
| 60 | + assert.True(t, isPodUpdateNetPolRelevant(&fakePod, newPod)) |
| 61 | + }) |
| 62 | + t.Run("Pod Host IP change should be detected as NetworkPolicy relevant", func(t *testing.T) { |
| 63 | + newPod := fakePod.DeepCopy() |
| 64 | + newPod.Status.HostIP = "10.0.0.2" |
| 65 | + assert.True(t, isPodUpdateNetPolRelevant(&fakePod, newPod)) |
| 66 | + }) |
| 67 | + t.Run("Pod Image change should NOT be detected as NetworkPolicy relevant", func(t *testing.T) { |
| 68 | + newPod := fakePod.DeepCopy() |
| 69 | + newPod.Spec.Containers[0].Image = "k8s.gcr.io/otherimage" |
| 70 | + assert.False(t, isPodUpdateNetPolRelevant(&fakePod, newPod)) |
| 71 | + }) |
| 72 | + t.Run("Pod Name change should NOT be detected as NetworkPolicy relevant", func(t *testing.T) { |
| 73 | + newPod := fakePod.DeepCopy() |
| 74 | + newPod.ObjectMeta.Name = "otherpod" |
| 75 | + assert.False(t, isPodUpdateNetPolRelevant(&fakePod, newPod)) |
| 76 | + }) |
| 77 | +} |
| 78 | + |
41 | 79 | func Test_isPodFinished(t *testing.T) { |
42 | 80 | t.Run("Failed pod should be detected as finished", func(t *testing.T) { |
43 | 81 | fakePod.Status.Phase = api.PodFailed |
|
0 commit comments