@@ -95,12 +95,20 @@ func TestProfileCommands(t *testing.T) {
9595 t .Errorf ("expected '* test-prof (test.looker.com:19999)', got %q" , out )
9696 }
9797
98- // 4. Add another profile
99- _ , err = executeCommand ("profile" , "add" , "test-prof2" , "--host" , "test2.looker.com" , "--port" , "20000" )
98+ // 4. Add another profile with --ssl=false
99+ _ , err = executeCommand ("profile" , "add" , "test-prof2" , "--host" , "test2.looker.com" , "--port" , "20000" , "--ssl=false" )
100100 if err != nil {
101101 t .Fatalf ("profile add failed: %v" , err )
102102 }
103103
104+ cfgCheck , err := config .Load ()
105+ if err != nil {
106+ t .Fatalf ("failed to load config: %v" , err )
107+ }
108+ if cfgCheck .Profiles ["test-prof2" ].SSL == nil || * cfgCheck .Profiles ["test-prof2" ].SSL != false {
109+ t .Errorf ("expected test-prof2 SSL to be false, got %v" , cfgCheck .Profiles ["test-prof2" ].SSL )
110+ }
111+
104112 // 5. List profiles (check default marker)
105113 out , err = executeCommand ("profile" , "ls" )
106114 if err != nil {
@@ -176,11 +184,13 @@ func TestInitClient_Profile(t *testing.T) {
176184 _ = RootCmd .PersistentFlags ().Set ("port" , "19999" )
177185 _ = RootCmd .PersistentFlags ().Set ("client-id" , "" )
178186 _ = RootCmd .PersistentFlags ().Set ("client-secret" , "" )
187+ _ = RootCmd .PersistentFlags ().Set ("ssl" , "true" )
179188 _ = RootCmd .PersistentFlags ().Set ("verify-ssl" , "true" )
180189 RootCmd .PersistentFlags ().Lookup ("host" ).Changed = false
181190 RootCmd .PersistentFlags ().Lookup ("port" ).Changed = false
182191 RootCmd .PersistentFlags ().Lookup ("client-id" ).Changed = false
183192 RootCmd .PersistentFlags ().Lookup ("client-secret" ).Changed = false
193+ RootCmd .PersistentFlags ().Lookup ("ssl" ).Changed = false
184194 RootCmd .PersistentFlags ().Lookup ("verify-ssl" ).Changed = false
185195 cfgProfile = ""
186196
@@ -307,4 +317,72 @@ func TestInitClient_Profile(t *testing.T) {
307317 t .Errorf ("expected verifySSL to be true from flag, got false" )
308318 }
309319 })
320+
321+ t .Run ("Profile ssl is used when flag is omitted" , func (t * testing.T ) {
322+ cfg , _ := config .Load ()
323+ falseVal := false
324+ cfg .Profiles ["prof-no-https" ] = config.Profile {
325+ Host : "profile-host.com" ,
326+ Port : "1234" ,
327+ ClientID : "prof-id" ,
328+ ClientSecret : "prof-sec" ,
329+ SSL : & falseVal ,
330+ }
331+ _ = cfg .Save ()
332+ _ = RootCmd .PersistentFlags ().Set ("profile" , "prof-no-https" )
333+ _ = RootCmd .PersistentFlags ().Set ("ssl" , "true" )
334+ RootCmd .PersistentFlags ().Lookup ("ssl" ).Changed = false
335+ defer func () {
336+ _ = RootCmd .PersistentFlags ().Set ("profile" , "" )
337+ cfgProfile = ""
338+ _ = RootCmd .PersistentFlags ().Set ("ssl" , "true" )
339+ if flag := RootCmd .PersistentFlags ().Lookup ("ssl" ); flag != nil {
340+ flag .Changed = false
341+ }
342+ }()
343+
344+ wrapper , err := initClient (context .Background (), false )
345+ if err != nil {
346+ t .Fatalf ("initClient failed: %v" , err )
347+ }
348+
349+ if wrapper .Session .Config .BaseUrl != "http://profile-host.com:1234" {
350+ t .Errorf ("expected base URL 'http://profile-host.com:1234', got '%s'" , wrapper .Session .Config .BaseUrl )
351+ }
352+ })
353+
354+ t .Run ("Explicit ssl flag overrides profile value" , func (t * testing.T ) {
355+ cfg , _ := config .Load ()
356+ falseVal := false
357+ cfg .Profiles ["prof-no-https" ] = config.Profile {
358+ Host : "profile-host.com" ,
359+ Port : "1234" ,
360+ ClientID : "prof-id" ,
361+ ClientSecret : "prof-sec" ,
362+ SSL : & falseVal ,
363+ }
364+ _ = cfg .Save ()
365+ _ = RootCmd .PersistentFlags ().Set ("profile" , "prof-no-https" )
366+ _ = RootCmd .PersistentFlags ().Set ("ssl" , "true" )
367+ RootCmd .PersistentFlags ().Lookup ("ssl" ).Changed = true
368+ defer func () {
369+ _ = RootCmd .PersistentFlags ().Set ("profile" , "" )
370+ cfgProfile = ""
371+ _ = RootCmd .PersistentFlags ().Set ("ssl" , "true" )
372+ RootCmd .PersistentFlags ().Lookup ("ssl" ).Changed = false
373+ _ = RootCmd .PersistentFlags ().Set ("ssl" , "true" )
374+ if flag := RootCmd .PersistentFlags ().Lookup ("ssl" ); flag != nil {
375+ flag .Changed = false
376+ }
377+ }()
378+
379+ wrapper , err := initClient (context .Background (), false )
380+ if err != nil {
381+ t .Fatalf ("initClient failed: %v" , err )
382+ }
383+
384+ if wrapper .Session .Config .BaseUrl != "https://profile-host.com:1234" {
385+ t .Errorf ("expected base URL 'https://profile-host.com:1234', got '%s'" , wrapper .Session .Config .BaseUrl )
386+ }
387+ })
310388}
0 commit comments