github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/integration/v7/selfcontained/api_command_test.go (about)

     1  package selfcontained_test
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/LukasHeimann/cloudfoundrycli/v8/api/cloudcontroller/ccv3"
     7  	"github.com/LukasHeimann/cloudfoundrycli/v8/integration/helpers"
     8  	"github.com/LukasHeimann/cloudfoundrycli/v8/integration/v7/selfcontained/fake"
     9  	"github.com/LukasHeimann/cloudfoundrycli/v8/util/configv3"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	"github.com/onsi/gomega/gexec"
    13  )
    14  
    15  var _ = Describe("cf api", func() {
    16  	var apiConfig fake.CFAPIConfig
    17  
    18  	BeforeEach(func() {
    19  		apiConfig = fake.CFAPIConfig{
    20  			Routes: map[string]fake.Response{
    21  				"GET /": {Code: http.StatusOK, Body: ccv3.Info{}},
    22  			},
    23  		}
    24  		apiServer.SetConfiguration(apiConfig)
    25  	})
    26  
    27  	JustBeforeEach(func() {
    28  		Eventually(helpers.CF("api", apiServer.URL())).Should(gexec.Exit(0))
    29  	})
    30  
    31  	It("disables cf-on-k8s in config", func() {
    32  		Expect(loadConfig().CFOnK8s.Enabled).To(BeFalse())
    33  	})
    34  
    35  	When("pointed to cf-on-k8s", func() {
    36  		BeforeEach(func() {
    37  			apiConfig.Routes["GET /"] = fake.Response{
    38  				Code: http.StatusOK, Body: ccv3.Info{CFOnK8s: true},
    39  			}
    40  			apiServer.SetConfiguration(apiConfig)
    41  		})
    42  
    43  		It("enables cf-on-k8s in config", func() {
    44  			Expect(loadConfig().CFOnK8s.Enabled).To(BeTrue())
    45  		})
    46  	})
    47  
    48  	When("already logged into a cf-on-k8s", func() {
    49  		BeforeEach(func() {
    50  			helpers.SetConfig(func(config *configv3.Config) {
    51  				config.ConfigFile.CFOnK8s.Enabled = true
    52  				config.ConfigFile.CFOnK8s.AuthInfo = "something"
    53  			})
    54  		})
    55  
    56  		It("disables cf-on-k8s in config and clears the auth-info", func() {
    57  			Expect(loadConfig().CFOnK8s).To(Equal(configv3.CFOnK8s{
    58  				Enabled:  false,
    59  				AuthInfo: "",
    60  			}))
    61  		})
    62  
    63  		When("pointed to cf-on-k8s", func() {
    64  			BeforeEach(func() {
    65  				apiConfig.Routes["GET /"] = fake.Response{
    66  					Code: http.StatusOK, Body: ccv3.Info{CFOnK8s: true},
    67  				}
    68  				apiServer.SetConfiguration(apiConfig)
    69  			})
    70  
    71  			It("clears the auth-info", func() {
    72  				Expect(loadConfig().CFOnK8s).To(Equal(configv3.CFOnK8s{
    73  					Enabled:  true,
    74  					AuthInfo: "",
    75  				}))
    76  			})
    77  		})
    78  	})
    79  })
    80  
    81  var _ = Describe("cf api --unset", func() {
    82  	BeforeEach(func() {
    83  		helpers.SetConfig(func(config *configv3.Config) {
    84  			config.ConfigFile.CFOnK8s.Enabled = true
    85  			config.ConfigFile.CFOnK8s.AuthInfo = "something"
    86  		})
    87  	})
    88  
    89  	JustBeforeEach(func() {
    90  		Eventually(helpers.CF("api", "--unset")).Should(gexec.Exit(0))
    91  	})
    92  
    93  	It("disables cf-on-k8s in config and clears the auth-info", func() {
    94  		Expect(loadConfig().CFOnK8s).To(Equal(configv3.CFOnK8s{
    95  			Enabled:  false,
    96  			AuthInfo: "",
    97  		}))
    98  	})
    99  })