@@ -7,76 +7,17 @@ import (
77
88	. "github.com/onsi/ginkgo/v2" 
99	. "github.com/onsi/gomega" 
10+ 	. "github.com/openmcp-project/controller-utils/pkg/testing/matchers" 
1011
1112	"github.com/openmcp-project/controller-utils/pkg/conditions" 
1213)
1314
14- type  conImpl  struct  {
15- 	status              bool 
16- 	conType             string 
17- 	reason              string 
18- 	message             string 
19- 	lastTransitionTime  time.Time 
20- }
21- 
22- func  newConImplWithValues (conType  string , status  bool , reason , message  string , lastTransitionTime  time.Time ) * conImpl  {
23- 	return  & conImpl {
24- 		conType :            conType ,
25- 		status :             status ,
26- 		reason :             reason ,
27- 		message :            message ,
28- 		lastTransitionTime : lastTransitionTime ,
29- 	}
30- }
31- 
32- var  _  conditions.Condition [bool ] =  & conImpl {}
33- 
34- func  (c  * conImpl ) GetLastTransitionTime () time.Time  {
35- 	return  c .lastTransitionTime 
36- }
37- 
38- func  (c  * conImpl ) GetType () string  {
39- 	return  c .conType 
40- }
41- 
42- func  (c  * conImpl ) GetStatus () bool  {
43- 	return  c .status 
44- }
45- 
46- func  (c  * conImpl ) GetReason () string  {
47- 	return  c .reason 
48- }
49- 
50- func  (c  * conImpl ) GetMessage () string  {
51- 	return  c .message 
52- }
53- 
54- func  (c  * conImpl ) SetStatus (status  bool ) {
55- 	c .status  =  status 
56- }
57- 
58- func  (c  * conImpl ) SetType (conType  string ) {
59- 	c .conType  =  conType 
60- }
61- 
62- func  (c  * conImpl ) SetLastTransitionTime (timestamp  time.Time ) {
63- 	c .lastTransitionTime  =  timestamp 
64- }
65- 
66- func  (c  * conImpl ) SetReason (reason  string ) {
67- 	c .reason  =  reason 
68- }
69- 
70- func  (c  * conImpl ) SetMessage (message  string ) {
71- 	c .message  =  message 
72- }
73- 
7415func  testConditionSet () []conditions.Condition [bool ] {
7516	now  :=  time .Now ().Add ((- 24 ) *  time .Hour )
7617	return  []conditions.Condition [bool ]{
77- 		newConImplWithValues ("true" , true , "reason" , "message" , now ),
78- 		newConImplWithValues ("false" , false , "reason" , "message" , now ),
79- 		newConImplWithValues ("alsoTrue" , true , "alsoReason" , "alsoMessage" , now ),
18+ 		NewConditionImplFromValues ("true" , true , "reason" , "message" , now ),
19+ 		NewConditionImplFromValues ("false" , false , "reason" , "message" , now ),
20+ 		NewConditionImplFromValues ("alsoTrue" , true , "alsoReason" , "alsoMessage" , now ),
8021	}
8122}
8223
@@ -134,7 +75,7 @@ var _ = Describe("Conditions", func() {
13475		It ("should update the condition (same value, keep other cons)" , func () {
13576			cons  :=  testConditionSet ()
13677			oldCon  :=  conditions .GetCondition (cons , "true" )
137- 			updated , changed  :=  conditions .ConditionUpdater (func () conditions. Condition [bool ] {  return   & conImpl {} } , cons , false ).UpdateCondition (oldCon .GetType (), oldCon .GetStatus (), "newReason" , "newMessage" ).Conditions ()
78+ 			updated , changed  :=  conditions .ConditionUpdater (NewCondition [bool ], cons , false ).UpdateCondition (oldCon .GetType (), oldCon .GetStatus (), "newReason" , "newMessage" ).Conditions ()
13879			Expect (changed ).To (BeTrue ())
13980			newCon  :=  conditions .GetCondition (updated , "true" )
14081			Expect (updated ).To (HaveLen (len (cons )))
@@ -151,7 +92,7 @@ var _ = Describe("Conditions", func() {
15192		It ("should update the condition (different value, keep other cons)" , func () {
15293			cons  :=  testConditionSet ()
15394			oldCon  :=  conditions .GetCondition (cons , "true" )
154- 			updated , changed  :=  conditions .ConditionUpdater (func () conditions. Condition [bool ] {  return   & conImpl {} } , cons , false ).UpdateCondition (oldCon .GetType (), ! oldCon .GetStatus (), "newReason" , "newMessage" ).Conditions ()
95+ 			updated , changed  :=  conditions .ConditionUpdater (NewCondition [bool ], cons , false ).UpdateCondition (oldCon .GetType (), ! oldCon .GetStatus (), "newReason" , "newMessage" ).Conditions ()
15596			Expect (changed ).To (BeTrue ())
15697			newCon  :=  conditions .GetCondition (updated , "true" )
15798			Expect (updated ).To (HaveLen (len (cons )))
@@ -169,7 +110,7 @@ var _ = Describe("Conditions", func() {
169110		It ("should update the condition (same value, discard other cons)" , func () {
170111			cons  :=  testConditionSet ()
171112			oldCon  :=  conditions .GetCondition (cons , "true" )
172- 			updated , changed  :=  conditions .ConditionUpdater (func () conditions. Condition [bool ] {  return   & conImpl {} } , cons , true ).UpdateCondition (oldCon .GetType (), oldCon .GetStatus (), "newReason" , "newMessage" ).Conditions ()
113+ 			updated , changed  :=  conditions .ConditionUpdater (NewCondition [bool ], cons , true ).UpdateCondition (oldCon .GetType (), oldCon .GetStatus (), "newReason" , "newMessage" ).Conditions ()
173114			Expect (changed ).To (BeTrue ())
174115			newCon  :=  conditions .GetCondition (updated , "true" )
175116			Expect (updated ).To (HaveLen (1 ))
@@ -186,7 +127,7 @@ var _ = Describe("Conditions", func() {
186127		It ("should update the condition (different value, discard other cons)" , func () {
187128			cons  :=  testConditionSet ()
188129			oldCon  :=  conditions .GetCondition (cons , "true" )
189- 			updated , changed  :=  conditions .ConditionUpdater (func () conditions. Condition [bool ] {  return   & conImpl {} } , cons , true ).UpdateCondition (oldCon .GetType (), ! oldCon .GetStatus (), "newReason" , "newMessage" ).Conditions ()
130+ 			updated , changed  :=  conditions .ConditionUpdater (NewCondition [bool ], cons , true ).UpdateCondition (oldCon .GetType (), ! oldCon .GetStatus (), "newReason" , "newMessage" ).Conditions ()
190131			Expect (changed ).To (BeTrue ())
191132			newCon  :=  conditions .GetCondition (updated , "true" )
192133			Expect (updated ).To (HaveLen (1 ))
@@ -203,16 +144,16 @@ var _ = Describe("Conditions", func() {
203144
204145		It ("should sort the conditions by type" , func () {
205146			cons  :=  []conditions.Condition [bool ]{
206- 				newConImplWithValues ("c" , true , "reason" , "message" , time .Now ()),
207- 				newConImplWithValues ("d" , true , "reason" , "message" , time .Now ()),
208- 				newConImplWithValues ("a" , true , "reason" , "message" , time .Now ()),
209- 				newConImplWithValues ("b" , true , "reason" , "message" , time .Now ()),
147+ 				NewConditionImplFromValues ("c" , true , "reason" , "message" , time .Now ()),
148+ 				NewConditionImplFromValues ("d" , true , "reason" , "message" , time .Now ()),
149+ 				NewConditionImplFromValues ("a" , true , "reason" , "message" , time .Now ()),
150+ 				NewConditionImplFromValues ("b" , true , "reason" , "message" , time .Now ()),
210151			}
211152			compareConditions  :=  func (a , b  conditions.Condition [bool ]) int  {
212153				return  strings .Compare (a .GetType (), b .GetType ())
213154			}
214155			Expect (slices .IsSortedFunc (cons , compareConditions )).To (BeFalse (), "conditions in the test object are already sorted, unable to test sorting" )
215- 			updated , changed  :=  conditions .ConditionUpdater (func () conditions. Condition [bool ] {  return   & conImpl {} } , cons , false ).Conditions ()
156+ 			updated , changed  :=  conditions .ConditionUpdater (NewCondition [bool ], cons , false ).Conditions ()
216157			Expect (changed ).To (BeFalse ())
217158			Expect (len (updated )).To (BeNumerically (">" , 1 ), "test object does not contain enough conditions to test sorting" )
218159			Expect (len (updated )).To (Equal (len (cons )))
@@ -221,32 +162,32 @@ var _ = Describe("Conditions", func() {
221162
222163		It ("should remove a condition" , func () {
223164			cons  :=  testConditionSet ()
224- 			updated , changed  :=  conditions .ConditionUpdater (func () conditions. Condition [bool ] {  return   & conImpl {} } , cons , false ).RemoveCondition ("true" ).Conditions ()
165+ 			updated , changed  :=  conditions .ConditionUpdater (NewCondition [bool ], cons , false ).RemoveCondition ("true" ).Conditions ()
225166			Expect (changed ).To (BeTrue ())
226167			Expect (updated ).To (HaveLen (len (cons ) -  1 ))
227168			con  :=  conditions .GetCondition (updated , "true" )
228169			Expect (con ).To (BeNil ())
229170
230171			// removing a condition that does not exist should not change anything 
231- 			updated , changed  =  conditions .ConditionUpdater (func () conditions. Condition [bool ] {  return   & conImpl {} } , cons , false ).RemoveCondition ("doesNotExist" ).Conditions ()
172+ 			updated , changed  =  conditions .ConditionUpdater (NewCondition [bool ], cons , false ).RemoveCondition ("doesNotExist" ).Conditions ()
232173			Expect (changed ).To (BeFalse ())
233174			Expect (updated ).To (HaveLen (len (cons )))
234175		})
235176
236177		It ("should not mark a condition as changed if it has the same values as before" , func () {
237178			cons  :=  testConditionSet ()
238179			con  :=  conditions .GetCondition (cons , "true" )
239- 			updated , changed  :=  conditions .ConditionUpdater (func () conditions. Condition [bool ] {  return   & conImpl {} } , cons , false ).UpdateCondition (con .GetType (), con .GetStatus (), con .GetReason (), con .GetMessage ()).Conditions ()
180+ 			updated , changed  :=  conditions .ConditionUpdater (NewCondition [bool ], cons , false ).UpdateCondition (con .GetType (), con .GetStatus (), con .GetReason (), con .GetMessage ()).Conditions ()
240181			Expect (changed ).To (BeFalse ())
241182			Expect (updated ).To (HaveLen (len (cons )))
242183		})
243184
244185		It ("should return that a condition exists only if it will be contained in the returned list" , func () {
245186			cons  :=  testConditionSet ()
246- 			updater  :=  conditions .ConditionUpdater (func () conditions. Condition [bool ] {  return   & conImpl {} } , cons , false )
187+ 			updater  :=  conditions .ConditionUpdater (NewCondition [bool ], cons , false )
247188			Expect (updater .HasCondition ("true" )).To (BeTrue ())
248189			Expect (updater .HasCondition ("doesNotExist" )).To (BeFalse ())
249- 			updater  =  conditions .ConditionUpdater (func () conditions. Condition [bool ] {  return   & conImpl {} } , cons , true )
190+ 			updater  =  conditions .ConditionUpdater (NewCondition [bool ], cons , true )
250191			Expect (updater .HasCondition ("true" )).To (BeFalse ())
251192			Expect (updater .HasCondition ("doesNotExist" )).To (BeFalse ())
252193			updater .UpdateCondition ("true" , true , "reason" , "message" )
0 commit comments