@@ -110,6 +110,34 @@ func TestResolveLocalRegistryEndpoint_Zot(t *testing.T) {
110110 expectError : true ,
111111 errContains : "missing 'http' section" ,
112112 },
113+ {
114+ name : "localhost address" ,
115+ zotJSON : `{"http":{"address":"localhost","port":"5000"}}` ,
116+ expected : "localhost:5000" ,
117+ },
118+ {
119+ name : "non-standard port" ,
120+ zotJSON : `{"http":{"address":"0.0.0.0","port":"12345"}}` ,
121+ expected : "0.0.0.0:12345" ,
122+ },
123+ {
124+ name : "http section with wrong type" ,
125+ zotJSON : `{"http":"wrong_type"}` ,
126+ expectError : true ,
127+ errContains : "missing 'http' section" ,
128+ },
129+ {
130+ name : "address with wrong type" ,
131+ zotJSON : `{"http":{"address":123,"port":"8585"}}` ,
132+ expectError : true ,
133+ errContains : "missing 'address' or 'port'" ,
134+ },
135+ {
136+ name : "port with wrong type" ,
137+ zotJSON : `{"http":{"address":"0.0.0.0","port":8585}}` ,
138+ expectError : true ,
139+ errContains : "missing 'address' or 'port'" ,
140+ },
113141 }
114142
115143 for _ , tt := range tests {
@@ -133,3 +161,115 @@ func TestResolveLocalRegistryEndpoint_Zot(t *testing.T) {
133161 })
134162 }
135163}
164+
165+ func TestMirrorFlags (t * testing.T ) {
166+ t .Run ("String method" , func (t * testing.T ) {
167+ flags := mirrorFlags {"cri1:registry1" , "cri2:registry2" }
168+ result := flags .String ()
169+ require .NotEmpty (t , result )
170+ require .Contains (t , result , "cri1:registry1" )
171+ require .Contains (t , result , "cri2:registry2" )
172+ })
173+
174+ t .Run ("Set method" , func (t * testing.T ) {
175+ var flags mirrorFlags
176+ err := flags .Set ("cri1:registry1" )
177+ require .NoError (t , err )
178+ require .Len (t , flags , 1 )
179+ require .Equal (t , "cri1:registry1" , flags [0 ])
180+
181+ err = flags .Set ("cri2:registry2" )
182+ require .NoError (t , err )
183+ require .Len (t , flags , 2 )
184+ })
185+
186+ t .Run ("Set multiple values" , func (t * testing.T ) {
187+ var flags mirrorFlags
188+ values := []string {"cri1:reg1" , "cri2:reg2,reg3" , "cri3:reg4" }
189+ for _ , v := range values {
190+ err := flags .Set (v )
191+ require .NoError (t , err )
192+ }
193+ require .Len (t , flags , 3 )
194+ })
195+ }
196+
197+ func TestSatelliteOptions (t * testing.T ) {
198+ t .Run ("default values" , func (t * testing.T ) {
199+ opts := SatelliteOptions {}
200+ require .False (t , opts .JSONLogging )
201+ require .Empty (t , opts .GroundControlURL )
202+ require .Empty (t , opts .Token )
203+ require .False (t , opts .UseUnsecure )
204+ require .False (t , opts .SPIFFEEnabled )
205+ require .Empty (t , opts .Mirrors )
206+ })
207+
208+ t .Run ("with values" , func (t * testing.T ) {
209+ opts := SatelliteOptions {
210+ JSONLogging : true ,
211+ GroundControlURL : "http://gc:8080" ,
212+ Token : "test-token" ,
213+ UseUnsecure : true ,
214+ SPIFFEEnabled : true ,
215+ }
216+ require .True (t , opts .JSONLogging )
217+ require .Equal (t , "http://gc:8080" , opts .GroundControlURL )
218+ require .Equal (t , "test-token" , opts .Token )
219+ require .True (t , opts .UseUnsecure )
220+ require .True (t , opts .SPIFFEEnabled )
221+ })
222+ }
223+
224+ func TestResolveLocalRegistryEndpoint_BYO_EdgeCases (t * testing.T ) {
225+ tests := []struct {
226+ name string
227+ url string
228+ expected string
229+ }{
230+ {
231+ name : "trailing slash preserved" ,
232+ url : "http://registry:5000/" ,
233+ expected : "registry:5000/" ,
234+ },
235+ {
236+ name : "multiple slashes preserved" ,
237+ url : "http://registry:5000///" ,
238+ expected : "registry:5000///" ,
239+ },
240+ {
241+ name : "with path" ,
242+ url : "http://registry:5000/v2" ,
243+ expected : "registry:5000/v2" ,
244+ },
245+ {
246+ name : "just hostname no port" ,
247+ url : "http://registry" ,
248+ expected : "registry" ,
249+ },
250+ {
251+ name : "https with port" ,
252+ url : "https://secure.registry.com:443" ,
253+ expected : "secure.registry.com:443" ,
254+ },
255+ }
256+
257+ for _ , tt := range tests {
258+ t .Run (tt .name , func (t * testing.T ) {
259+ cfg := & config.Config {
260+ AppConfig : config.AppConfig {
261+ BringOwnRegistry : true ,
262+ LocalRegistryCredentials : config.RegistryCredentials {
263+ URL : config .URL (tt .url ),
264+ },
265+ },
266+ ZotConfigRaw : json .RawMessage (`{}` ),
267+ }
268+ cm := newTestConfigManager (t , cfg )
269+
270+ endpoint , err := resolveLocalRegistryEndpoint (cm )
271+ require .NoError (t , err )
272+ require .Equal (t , tt .expected , endpoint )
273+ })
274+ }
275+ }
0 commit comments