@@ -36,12 +36,13 @@ func TestGenerateStatus(t *testing.T) {
36
36
{
37
37
Type : testConditionA ,
38
38
Status : true ,
39
- Transition : time .Now (),
39
+ Transition : time .Unix (500 , 500 ),
40
+ Reason : "initial reason" ,
40
41
},
41
42
{
42
43
Type : testConditionB ,
43
44
Status : false ,
44
- Transition : time .Now ( ),
45
+ Transition : time .Unix ( 500 , 500 ),
45
46
},
46
47
}
47
48
logs := []* kerntypes.KernelLog {
@@ -79,6 +80,26 @@ func TestGenerateStatus(t *testing.T) {
79
80
},
80
81
},
81
82
},
83
+ // Should not update transition time when status and reason are not changed.
84
+ {
85
+ rule : kerntypes.Rule {
86
+ Type : kerntypes .Perm ,
87
+ Condition : testConditionA ,
88
+ Reason : "initial reason" ,
89
+ },
90
+ expected : types.Status {
91
+ Source : testSource ,
92
+ Conditions : []types.Condition {
93
+ {
94
+ Type : testConditionA ,
95
+ Status : true ,
96
+ Transition : time .Unix (500 , 500 ),
97
+ Reason : "initial reason" ,
98
+ },
99
+ initConditions [1 ],
100
+ },
101
+ },
102
+ },
82
103
{
83
104
rule : kerntypes.Rule {
84
105
Type : kerntypes .Temp ,
@@ -100,7 +121,9 @@ func TestGenerateStatus(t *testing.T) {
100
121
config : MonitorConfig {
101
122
Source : testSource ,
102
123
},
103
- conditions : initConditions ,
124
+ // Copy the init conditions to make sure it's not changed
125
+ // during the test.
126
+ conditions : append ([]types.Condition {}, initConditions ... ),
104
127
}
105
128
got := k .generateStatus (logs , test .rule )
106
129
if ! reflect .DeepEqual (& test .expected , got ) {
0 commit comments