@@ -316,4 +316,111 @@ status: {}
316316 assert .NotEmpty (t , result1 )
317317 assert .NotEmpty (t , result2 )
318318 })
319+
320+ // Test IsAirgap template function
321+ t .Run ("IsAirgap template function" , func (t * testing.T ) {
322+ airgapConfig := kotsv1beta1.Config {
323+ TypeMeta : metav1.TypeMeta {
324+ APIVersion : "kots.io/v1beta1" ,
325+ Kind : "Config" ,
326+ },
327+ ObjectMeta : metav1.ObjectMeta {
328+ Name : "airgap-test-config" ,
329+ },
330+ Spec : kotsv1beta1.ConfigSpec {
331+ Groups : []kotsv1beta1.ConfigGroup {
332+ {
333+ Name : "airgap_tests" ,
334+ Title : "Airgap Tests" ,
335+ Items : []kotsv1beta1.ConfigItem {
336+ {
337+ Name : "airgap_mode" ,
338+ Title : "Airgap Mode" ,
339+ Type : "text" ,
340+ Default : multitype .FromString (`{{repl IsAirgap | ternary "airgap" "online" }}` ),
341+ Value : multitype .FromString (`{{repl IsAirgap }}` ),
342+ },
343+ {
344+ Name : "installation_type" ,
345+ Title : "Installation Type" ,
346+ Type : "text" ,
347+ Default : multitype .FromString (`{{repl if IsAirgap }}Airgap Installation{{repl else }}Online Installation{{repl end }}` ),
348+ Value : multitype .FromString (`{{repl if IsAirgap }}Disconnected{{repl else }}Connected{{repl end }}` ),
349+ },
350+ },
351+ },
352+ },
353+ },
354+ }
355+
356+ // Test with airgap bundle set (airgap installation)
357+ t .Run ("with airgap bundle" , func (t * testing.T ) {
358+ manager , err := NewAppConfigManager (airgapConfig , WithIsAirgap (true ))
359+ require .NoError (t , err )
360+ require .NotNil (t , manager )
361+
362+ result , err := manager .executeConfigTemplate (types.AppConfigValues {})
363+ require .NoError (t , err )
364+ require .NotEmpty (t , result )
365+
366+ expectedYAML := `apiVersion: kots.io/v1beta1
367+ kind: Config
368+ metadata:
369+ name: airgap-test-config
370+ spec:
371+ groups:
372+ - items:
373+ - default: airgap
374+ name: airgap_mode
375+ title: Airgap Mode
376+ type: text
377+ value: "true"
378+ - default: Airgap Installation
379+ name: installation_type
380+ title: Installation Type
381+ type: text
382+ value: Disconnected
383+ name: airgap_tests
384+ title: Airgap Tests
385+ status: {}
386+ `
387+
388+ assert .Equal (t , expectedYAML , result )
389+ })
390+
391+ // Test without airgap bundle (online installation)
392+ t .Run ("without airgap bundle" , func (t * testing.T ) {
393+ manager , err := NewAppConfigManager (airgapConfig )
394+ require .NoError (t , err )
395+ require .NotNil (t , manager )
396+
397+ result , err := manager .executeConfigTemplate (types.AppConfigValues {})
398+ require .NoError (t , err )
399+ require .NotEmpty (t , result )
400+
401+ expectedYAML := `apiVersion: kots.io/v1beta1
402+ kind: Config
403+ metadata:
404+ name: airgap-test-config
405+ spec:
406+ groups:
407+ - items:
408+ - default: online
409+ name: airgap_mode
410+ title: Airgap Mode
411+ type: text
412+ value: "false"
413+ - default: Online Installation
414+ name: installation_type
415+ title: Installation Type
416+ type: text
417+ value: Connected
418+ name: airgap_tests
419+ title: Airgap Tests
420+ status: {}
421+ `
422+
423+ assert .Equal (t , expectedYAML , result )
424+ })
425+ })
319426}
0 commit comments