Use go-cmp to compare pods to suppress duplicate updates
Rather than copying the pods, this uses go-cmp and filters out the paths which should not be compared.
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"time"
|
||||
|
||||
"gotest.tools/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func TestPodControllerExitOnContextCancel(t *testing.T) {
|
||||
@@ -42,3 +44,49 @@ func TestPodControllerExitOnContextCancel(t *testing.T) {
|
||||
}
|
||||
assert.NilError(t, tc.Err())
|
||||
}
|
||||
|
||||
func TestCompareResourceVersion(t *testing.T) {
|
||||
p1 := &corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
}
|
||||
p2 := &corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
}
|
||||
assert.Assert(t, podsEffectivelyEqual(p1, p2))
|
||||
}
|
||||
|
||||
func TestCompareStatus(t *testing.T) {
|
||||
p1 := &corev1.Pod{
|
||||
Status: corev1.PodStatus{
|
||||
Phase: corev1.PodRunning,
|
||||
},
|
||||
}
|
||||
p2 := &corev1.Pod{
|
||||
Status: corev1.PodStatus{
|
||||
Phase: corev1.PodFailed,
|
||||
},
|
||||
}
|
||||
assert.Assert(t, podsEffectivelyEqual(p1, p2))
|
||||
}
|
||||
|
||||
func TestCompareLabels(t *testing.T) {
|
||||
p1 := &corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar1",
|
||||
},
|
||||
},
|
||||
}
|
||||
p2 := &corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar2",
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.Assert(t, !podsEffectivelyEqual(p1, p2))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user