@@ -575,6 +575,66 @@ function common_func {
575575 want : map [string ]string {},
576576 error : true ,
577577 },
578+ {
579+ name : "CommonTemplates are injected" ,
580+ tmpl : Template {
581+ Name : "testservice" ,
582+ Namespace : "somenamespace" ,
583+ Type : TemplateTypeConfig ,
584+ InstanceType : "testservice" ,
585+ CommonTemplates : []string {"ssl.conf" },
586+ ConfigOptions : map [string ]any {
587+ "ServiceUser" : "foo" ,
588+ "Count" : 1 ,
589+ "Upper" : "BAR" ,
590+ },
591+ },
592+ want : map [string ]string {
593+ "bar.conf" : "[DEFAULT]\n state_path = /var/lib/nova\n debug=true\n some_parameter_with_brackets=[test]\n compute_driver = libvirt.LibvirtDriver\n \n [oslo_concurrency]\n lock_path = /var/lib/nova/tmp\n " ,
594+ "config.json" : "{\n \" command\" : \" /usr/sbin/httpd -DFOREGROUND\" ,\n }\n " ,
595+ "foo.conf" : "username = foo\n count = 1\n add = 3\n lower = bar\n " ,
596+ "ssl.conf" : "" , // placeholder, replaced below
597+ },
598+ error : false ,
599+ },
600+ {
601+ name : "Unknown CommonTemplate returns error" ,
602+ tmpl : Template {
603+ Name : "testservice" ,
604+ Namespace : "somenamespace" ,
605+ Type : TemplateTypeConfig ,
606+ InstanceType : "testservice" ,
607+ CommonTemplates : []string {"sls.conf" },
608+ },
609+ want : nil ,
610+ error : true ,
611+ },
612+ {
613+ name : "Local service templates take precedence" ,
614+ tmpl : Template {
615+ Name : "override" ,
616+ Namespace : "somenamespace" ,
617+ Type : TemplateTypeConfig ,
618+ InstanceType : "override" ,
619+ CommonTemplates : []string {"ssl.conf" },
620+ ConfigOptions : map [string ]any {},
621+ },
622+ want : map [string ]string {
623+ "ssl.conf" : "# operator-specific ssl.conf override\n SSLProtocol -all +TLSv1.3\n " ,
624+ },
625+ error : false ,
626+ },
627+ }
628+
629+ // Fill in the expected ssl.conf content for the CommonTemplates test
630+ commonTmpls , err := GetCommonTemplates (map [string ]any {})
631+ if err != nil {
632+ panic ("Failed to get common templates: " + err .Error ())
633+ }
634+ for i , tt := range tests {
635+ if v , ok := tt .want ["ssl.conf" ]; ok && v == "" {
636+ tests [i ].want ["ssl.conf" ] = commonTmpls ["ssl.conf" ]
637+ }
578638 }
579639
580640 for _ , tt := range tests {
@@ -618,3 +678,16 @@ baz=1
618678
619679 g .Expect (cleaned2 ).To (Equal (cleaned ))
620680}
681+
682+ func TestGetCommonTemplates (t * testing.T ) {
683+ t .Run ("Returns ssl.conf" , func (t * testing.T ) {
684+ g := NewWithT (t )
685+
686+ result , err := GetCommonTemplates (map [string ]interface {}{})
687+ g .Expect (err ).NotTo (HaveOccurred ())
688+ g .Expect (result ).To (HaveKey ("ssl.conf" ))
689+ g .Expect (result ["ssl.conf" ]).To (ContainSubstring ("mod_ssl" ))
690+ g .Expect (result ["ssl.conf" ]).To (ContainSubstring ("SSLProtocol" ))
691+ g .Expect (result ["ssl.conf" ]).To (ContainSubstring ("SSLCipherSuite" ))
692+ })
693+ }
0 commit comments