@@ -29,18 +29,20 @@ func TestSetStatusCondition(t *testing.T) {
29
29
oneHourAfter := time .Now ().Add (1 * time .Hour )
30
30
31
31
tests := []struct {
32
- name string
33
- conditions []metav1.Condition
34
- toAdd metav1.Condition
35
- expected []metav1.Condition
32
+ name string
33
+ conditions []metav1.Condition
34
+ toAdd metav1.Condition
35
+ expectChanged bool
36
+ expected []metav1.Condition
36
37
}{
37
38
{
38
39
name : "should-add" ,
39
40
conditions : []metav1.Condition {
40
41
{Type : "first" },
41
42
{Type : "third" },
42
43
},
43
- toAdd : metav1.Condition {Type : "second" , Status : metav1 .ConditionTrue , LastTransitionTime : metav1.Time {Time : oneHourBefore }, Reason : "reason" , Message : "message" },
44
+ toAdd : metav1.Condition {Type : "second" , Status : metav1 .ConditionTrue , LastTransitionTime : metav1.Time {Time : oneHourBefore }, Reason : "reason" , Message : "message" },
45
+ expectChanged : true ,
44
46
expected : []metav1.Condition {
45
47
{Type : "first" },
46
48
{Type : "third" },
@@ -54,7 +56,8 @@ func TestSetStatusCondition(t *testing.T) {
54
56
{Type : "second" , Status : metav1 .ConditionFalse },
55
57
{Type : "third" },
56
58
},
57
- toAdd : metav1.Condition {Type : "second" , Status : metav1 .ConditionTrue , LastTransitionTime : metav1.Time {Time : oneHourBefore }, Reason : "reason" , Message : "message" },
59
+ toAdd : metav1.Condition {Type : "second" , Status : metav1 .ConditionTrue , LastTransitionTime : metav1.Time {Time : oneHourBefore }, Reason : "reason" , Message : "message" },
60
+ expectChanged : true ,
58
61
expected : []metav1.Condition {
59
62
{Type : "first" },
60
63
{Type : "second" , Status : metav1 .ConditionTrue , LastTransitionTime : metav1.Time {Time : oneHourBefore }, Reason : "reason" , Message : "message" },
@@ -68,18 +71,36 @@ func TestSetStatusCondition(t *testing.T) {
68
71
{Type : "second" , Status : metav1 .ConditionTrue , LastTransitionTime : metav1.Time {Time : oneHourBefore }},
69
72
{Type : "third" },
70
73
},
71
- toAdd : metav1.Condition {Type : "second" , Status : metav1 .ConditionTrue , LastTransitionTime : metav1.Time {Time : oneHourAfter }, Reason : "reason" , Message : "message" , ObservedGeneration : 3 },
74
+ toAdd : metav1.Condition {Type : "second" , Status : metav1 .ConditionTrue , LastTransitionTime : metav1.Time {Time : oneHourAfter }, Reason : "reason" , Message : "message" , ObservedGeneration : 3 },
75
+ expectChanged : true ,
72
76
expected : []metav1.Condition {
73
77
{Type : "first" },
74
78
{Type : "second" , Status : metav1 .ConditionTrue , LastTransitionTime : metav1.Time {Time : oneHourBefore }, Reason : "reason" , Message : "message" , ObservedGeneration : 3 },
75
79
{Type : "third" },
76
80
},
77
81
},
82
+ {
83
+ name : "nothing changes" ,
84
+ conditions : []metav1.Condition {{
85
+ Type : "type" ,
86
+ Status : metav1 .ConditionTrue ,
87
+ LastTransitionTime : metav1.Time {Time : oneHourBefore },
88
+ }},
89
+ toAdd : metav1.Condition {Type : "type" , Status : metav1 .ConditionTrue , LastTransitionTime : metav1.Time {Time : oneHourBefore }},
90
+ expected : []metav1.Condition {{
91
+ Type : "type" ,
92
+ Status : metav1 .ConditionTrue ,
93
+ LastTransitionTime : metav1.Time {Time : oneHourBefore },
94
+ }},
95
+ },
78
96
}
79
97
80
98
for _ , test := range tests {
81
99
t .Run (test .name , func (t * testing.T ) {
82
- SetStatusCondition (& test .conditions , test .toAdd )
100
+ changed := SetStatusCondition (& test .conditions , test .toAdd )
101
+ if test .expectChanged != changed {
102
+ t .Errorf ("expectChanged=%t != changed=%t" , test .expectChanged , changed )
103
+ }
83
104
if ! reflect .DeepEqual (test .conditions , test .expected ) {
84
105
t .Error (test .conditions )
85
106
}
@@ -92,6 +113,7 @@ func TestRemoveStatusCondition(t *testing.T) {
92
113
name string
93
114
conditions []metav1.Condition
94
115
conditionType string
116
+ expectRemoval bool
95
117
expected []metav1.Condition
96
118
}{
97
119
{
@@ -102,6 +124,7 @@ func TestRemoveStatusCondition(t *testing.T) {
102
124
{Type : "third" },
103
125
},
104
126
conditionType : "second" ,
127
+ expectRemoval : true ,
105
128
expected : []metav1.Condition {
106
129
{Type : "first" },
107
130
{Type : "third" },
@@ -131,7 +154,10 @@ func TestRemoveStatusCondition(t *testing.T) {
131
154
132
155
for _ , test := range tests {
133
156
t .Run (test .name , func (t * testing.T ) {
134
- RemoveStatusCondition (& test .conditions , test .conditionType )
157
+ removed := RemoveStatusCondition (& test .conditions , test .conditionType )
158
+ if test .expectRemoval != removed {
159
+ t .Errorf ("expectRemoval=%t != removal=%t" , test .expectRemoval , removed )
160
+ }
135
161
if ! reflect .DeepEqual (test .conditions , test .expected ) {
136
162
t .Error (test .conditions )
137
163
}
0 commit comments