@@ -2,7 +2,6 @@ package action_test
22
33import (
44 "context"
5- "maps"
65
76 . "github.com/onsi/ginkgo"
87 . "github.com/onsi/gomega"
@@ -60,8 +59,8 @@ var _ = Describe("CatalogUpdate", func() {
6059 testCatalog := buildCatalog (
6160 "testCatalog" ,
6261 withCatalogSourceType (olmv1 .SourceTypeImage ),
63- withCatalogPollInterval (5 , "testCatalog" ),
64- withCatalogSourcePriority (1 ),
62+ withCatalogPollInterval (pointerToInt ( 5 ) ),
63+ withCatalogSourcePriority (pointerToInt32 ( 1 ) ),
6564 withCatalogImageRef ("quay.io/myrepo/myimage" ),
6665 withCatalogAvailabilityMode (olmv1 .AvailabilityModeAvailable ),
6766 withCatalogLabels (map [string ]string {"foo" : "bar" }),
@@ -70,35 +69,53 @@ var _ = Describe("CatalogUpdate", func() {
7069
7170 updater := internalaction .NewCatalogUpdate (& cfg )
7271 updater .CatalogName = "testCatalog"
73- updater .Priority = int32 (1 )
72+ updater .Priority = pointerToInt32 (1 )
7473 updater .Labels = map [string ]string {"abc" : "xyz" }
7574 updater .AvailabilityMode = string (olmv1 .AvailabilityModeAvailable )
76- updater .PollIntervalMinutes = int (5 )
75+ updater .PollIntervalMinutes = pointerToInt (5 )
7776 catalog , err := updater .Run (context .TODO ())
7877
7978 Expect (err ).To (BeNil ())
8079 Expect (testCatalog ).NotTo (BeNil ())
81- Expect (maps .Equal (catalog .Labels , updater .Labels )).To (BeTrue ())
82- Expect (catalog .Spec .Priority ).To (Equal (updater .Priority ))
80+ Expect (catalog .Labels ).To (HaveKeyWithValue ("foo" , "bar" )) //existing
81+ Expect (catalog .Labels ).To (HaveKeyWithValue ("abc" , "xyz" )) //newly added
82+ Expect (catalog .Spec .Priority ).To (Equal (* updater .Priority ))
8383 Expect (catalog .Spec .Source .Image .PollIntervalMinutes ).ToNot (BeNil ())
84- Expect (* catalog .Spec .Source .Image .PollIntervalMinutes ).To (Equal (int ( 5 ) ))
84+ Expect (* catalog .Spec .Source .Image .PollIntervalMinutes ).To (Equal (* updater . PollIntervalMinutes ))
8585 Expect (catalog .Spec .AvailabilityMode ).To (Equal (olmv1 .AvailabilityMode (updater .AvailabilityMode )))
8686 })
8787
8888 It ("unsets the poll interval field when set to 0" , func () {
8989 testCatalog := buildCatalog (
9090 "test" ,
9191 withCatalogSourceType (olmv1 .SourceTypeImage ),
92- withCatalogPollInterval (7 , "test" ),
92+ withCatalogPollInterval (pointerToInt ( 7 ) ),
9393 withCatalogImageRef ("quay.io/myrepo/myimage" ),
94- withCatalogAvailabilityMode (olmv1 .AvailabilityModeAvailable ),
95- withCatalogLabels (map [string ]string {"foo" : "bar" }),
9694 )
9795 cfg := setupEnv (testCatalog )
9896
9997 updater := internalaction .NewCatalogUpdate (& cfg )
10098 updater .CatalogName = "test"
101- updater .PollIntervalMinutes = 0
99+ updater .PollIntervalMinutes = pointerToInt (- 1 )
100+ catalog , err := updater .Run (context .TODO ())
101+
102+ Expect (err ).NotTo (HaveOccurred ())
103+ Expect (catalog .Spec .Source .Image .PollIntervalMinutes ).To (BeNil ())
104+ })
105+
106+ It ("unsets the poll interval field when set to 0" , func () {
107+ testCatalog := buildCatalog (
108+ "test" ,
109+ withCatalogSourceType (olmv1 .SourceTypeImage ),
110+ withCatalogPollInterval (pointerToInt (10 )),
111+ withCatalogImageRef ("quay.io/myrepo/myimage" ),
112+ )
113+ cfg := setupEnv (testCatalog )
114+
115+ updater := internalaction .NewCatalogUpdate (& cfg )
116+ updater .CatalogName = "test"
117+ updater .PollIntervalMinutes = pointerToInt (0 )
118+
102119 catalog , err := updater .Run (context .TODO ())
103120
104121 Expect (err ).NotTo (HaveOccurred ())
@@ -110,8 +127,8 @@ var _ = Describe("CatalogUpdate", func() {
110127 "test" ,
111128 withCatalogSourceType (olmv1 .SourceTypeImage ),
112129 withCatalogImageRef ("quay.io/myrepo/myimage" ),
113- withCatalogPollInterval (10 , "my-catalog" ),
114- withCatalogSourcePriority (5 ),
130+ withCatalogPollInterval (pointerToInt ( 10 ) ),
131+ withCatalogSourcePriority (pointerToInt32 ( 5 ) ),
115132 withCatalogAvailabilityMode (olmv1 .AvailabilityModeAvailable ),
116133 withCatalogLabels (map [string ]string {"foo" : "bar" }),
117134 )
@@ -143,4 +160,59 @@ var _ = Describe("CatalogUpdate", func() {
143160 Expect (err .Error ()).To (ContainSubstring ("invalid image reference" ))
144161 })
145162
163+ It ("preserves existing catalog values if Priority and PollIntervalMinutes are nil" , func () {
164+ testCatalog := buildCatalog (
165+ "test" ,
166+ withCatalogSourceType (olmv1 .SourceTypeImage ),
167+ withCatalogPollInterval (pointerToInt (15 )),
168+ withCatalogSourcePriority (pointerToInt32 (10 )),
169+ withCatalogImageRef ("quay.io/myrepo/image" ),
170+ )
171+
172+ cfg := setupEnv (testCatalog )
173+
174+ updater := internalaction .NewCatalogUpdate (& cfg )
175+ updater .CatalogName = "test"
176+ updater .Priority = nil
177+ updater .PollIntervalMinutes = nil
178+
179+ catalog , err := updater .Run (context .TODO ())
180+
181+ Expect (err ).NotTo (HaveOccurred ())
182+ Expect (catalog .Spec .Priority ).To (Equal (int32 (10 )))
183+ Expect (* catalog .Spec .Source .Image .PollIntervalMinutes ).To (Equal (15 ))
184+ })
185+
186+ It ("removes labels with empty values and merges the rest" , func () {
187+ initial := map [string ]string {"foo" : "bar" , "remove" : "yes" }
188+ testCatalog := buildCatalog (
189+ "test" ,
190+ withCatalogSourceType (olmv1 .SourceTypeImage ),
191+ withCatalogLabels (initial ),
192+ )
193+ cfg := setupEnv (testCatalog )
194+
195+ updater := internalaction .NewCatalogUpdate (& cfg )
196+ updater .CatalogName = "test"
197+ updater .Labels = map [string ]string {
198+ "remove" : "" ,
199+ "new" : "label" ,
200+ }
201+ catalog , err := updater .Run (context .TODO ())
202+ Expect (err ).NotTo (HaveOccurred ())
203+
204+ Expect (catalog .Labels ).To (Equal (map [string ]string {
205+ "foo" : "bar" ,
206+ "new" : "label" ,
207+ }))
208+ })
209+
146210})
211+
212+ func pointerToInt32 (i int32 ) * int32 {
213+ return & i
214+ }
215+
216+ func pointerToInt (i int ) * int {
217+ return & i
218+ }
0 commit comments