@@ -11,7 +11,8 @@ import (
11
11
)
12
12
13
13
func TestMergeConditions (t * testing.T ) {
14
- now := metav1 .NewTime (time .Unix (0 , 0 ))
14
+ oldTime := metav1 .NewTime (time .Unix (0 , 0 ))
15
+ now := metav1 .NewTime (time .Unix (10 , 0 ))
15
16
tt := []struct {
16
17
desc string
17
18
old []metav1.Condition
@@ -37,25 +38,53 @@ func TestMergeConditions(t *testing.T) {
37
38
{
38
39
desc : "reset old condition" ,
39
40
old : []metav1.Condition {
40
- conditionPending ,
41
+ {
42
+ Type : conditionPending .Type ,
43
+ Status : metav1 .ConditionTrue ,
44
+ LastTransitionTime : oldTime ,
45
+ Reason : conditionPending .Reason ,
46
+ Message : conditionPending .Message ,
47
+ },
41
48
},
42
49
active : []metav1.Condition {
43
50
conditionReady ,
44
51
},
45
52
wantMerged : []metav1.Condition {
53
+ {
54
+ Type : conditionReady .Type ,
55
+ Status : metav1 .ConditionTrue ,
56
+ LastTransitionTime : now ,
57
+ Reason : conditionReady .Reason ,
58
+ Message : conditionReady .Message ,
59
+ },
46
60
{
47
61
Type : conditionPending .Type ,
48
62
Status : metav1 .ConditionFalse ,
49
63
LastTransitionTime : now ,
50
64
Reason : conditionPending .Reason ,
51
65
Message : conditionPending .Message ,
52
66
},
67
+ },
68
+ },
69
+ {
70
+ desc : "keep transition time of old condition" ,
71
+ old : []metav1.Condition {
53
72
{
54
- Type : conditionReady .Type ,
55
- Status : metav1 .ConditionTrue ,
56
- LastTransitionTime : now ,
57
- Reason : conditionReady .Reason ,
58
- Message : conditionReady .Message ,
73
+ Type : conditionPending .Type ,
74
+ Status : metav1 .ConditionFalse ,
75
+ LastTransitionTime : oldTime ,
76
+ Reason : conditionPending .Reason ,
77
+ Message : conditionPending .Message ,
78
+ },
79
+ },
80
+ active : []metav1.Condition {},
81
+ wantMerged : []metav1.Condition {
82
+ {
83
+ Type : conditionPending .Type ,
84
+ Status : metav1 .ConditionFalse ,
85
+ LastTransitionTime : oldTime ,
86
+ Reason : conditionPending .Reason ,
87
+ Message : conditionPending .Message ,
59
88
},
60
89
},
61
90
},
@@ -72,7 +101,7 @@ func TestMergeConditions(t *testing.T) {
72
101
{
73
102
Type : conditionPending .Type ,
74
103
Status : metav1 .ConditionFalse ,
75
- LastTransitionTime : now ,
104
+ LastTransitionTime : oldTime ,
76
105
Reason : conditionPending .Reason ,
77
106
Message : conditionPending .Message ,
78
107
},
@@ -93,13 +122,56 @@ func TestMergeConditions(t *testing.T) {
93
122
Reason : conditionReady .Reason ,
94
123
Message : conditionReady .Message ,
95
124
},
125
+ {
126
+ Type : string (lokiv1 .ConditionWarning ),
127
+ Status : metav1 .ConditionTrue ,
128
+ LastTransitionTime : now ,
129
+ Reason : "test-warning" ,
130
+ Message : "test-warning-message" ,
131
+ },
96
132
{
97
133
Type : conditionPending .Type ,
98
134
Status : metav1 .ConditionFalse ,
99
- LastTransitionTime : now ,
135
+ LastTransitionTime : oldTime ,
100
136
Reason : conditionPending .Reason ,
101
137
Message : conditionPending .Message ,
102
138
},
139
+ },
140
+ },
141
+ {
142
+ desc : "remove duplicates" ,
143
+ old : []metav1.Condition {
144
+ {
145
+ Type : conditionReady .Type ,
146
+ Status : metav1 .ConditionTrue ,
147
+ LastTransitionTime : now ,
148
+ Reason : conditionReady .Reason ,
149
+ Message : conditionReady .Message ,
150
+ },
151
+ {
152
+ Type : conditionReady .Type ,
153
+ Status : metav1 .ConditionTrue ,
154
+ LastTransitionTime : now ,
155
+ Reason : conditionReady .Reason ,
156
+ Message : conditionReady .Message ,
157
+ },
158
+ },
159
+ active : []metav1.Condition {
160
+ conditionReady ,
161
+ {
162
+ Type : string (lokiv1 .ConditionWarning ),
163
+ Reason : "test-warning" ,
164
+ Message : "test-warning-message" ,
165
+ },
166
+ },
167
+ wantMerged : []metav1.Condition {
168
+ {
169
+ Type : conditionReady .Type ,
170
+ Status : metav1 .ConditionTrue ,
171
+ LastTransitionTime : now ,
172
+ Reason : conditionReady .Reason ,
173
+ Message : conditionReady .Message ,
174
+ },
103
175
{
104
176
Type : string (lokiv1 .ConditionWarning ),
105
177
Status : metav1 .ConditionTrue ,
0 commit comments