github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v2action/target_test.go (about) 1 package v2action_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/actor/v2action" 5 "code.cloudfoundry.org/cli/actor/v2action/v2actionfakes" 6 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("Targeting", func() { 12 var ( 13 actor *Actor 14 skipSSLValidation bool 15 16 fakeCloudControllerClient *v2actionfakes.FakeCloudControllerClient 17 fakeConfig *v2actionfakes.FakeConfig 18 settings TargetSettings 19 ) 20 21 BeforeEach(func() { 22 fakeCloudControllerClient = new(v2actionfakes.FakeCloudControllerClient) 23 fakeConfig = new(v2actionfakes.FakeConfig) 24 actor = NewActor(fakeCloudControllerClient, nil, fakeConfig) 25 26 settings = TargetSettings{ 27 SkipSSLValidation: skipSSLValidation, 28 } 29 }) 30 31 Describe("ClearTarget", func() { 32 It("clears all the target information", func() { 33 actor.ClearTarget() 34 Expect(fakeConfig.SetTargetInformationCallCount()).To(Equal(1)) 35 api, apiVersion, auth, minCLIVersion, doppler, routing, sslDisabled := fakeConfig.SetTargetInformationArgsForCall(0) 36 37 Expect(api).To(BeEmpty()) 38 Expect(apiVersion).To(BeEmpty()) 39 Expect(auth).To(BeEmpty()) 40 Expect(minCLIVersion).To(BeEmpty()) 41 Expect(doppler).To(BeEmpty()) 42 Expect(routing).To(BeEmpty()) 43 Expect(sslDisabled).To(BeFalse()) 44 }) 45 46 It("clears all the token information", func() { 47 actor.ClearTarget() 48 49 Expect(fakeConfig.SetTokenInformationCallCount()).To(Equal(1)) 50 accessToken, refreshToken, sshOAuthClient := fakeConfig.SetTokenInformationArgsForCall(0) 51 52 Expect(accessToken).To(BeEmpty()) 53 Expect(refreshToken).To(BeEmpty()) 54 Expect(sshOAuthClient).To(BeEmpty()) 55 }) 56 }) 57 58 Describe("MinCLIVersion", func() { 59 var version string 60 61 BeforeEach(func() { 62 fakeCloudControllerClient.MinCLIVersionReturns("10.9.8") 63 }) 64 65 JustBeforeEach(func() { 66 version = actor.MinCLIVersion() 67 }) 68 69 It("returns the version that the API reports", func() { 70 Expect(version).To(Equal("10.9.8")) 71 }) 72 }) 73 74 Describe("SetTarget", func() { 75 var expectedAPI, expectedAPIVersion, expectedAuth, expectedMinCLIVersion, expectedDoppler, expectedRouting string 76 77 BeforeEach(func() { 78 expectedAPI = "https://api.foo.com" 79 expectedAPIVersion = "2.59.0" 80 expectedAuth = "https://login.foo.com" 81 expectedMinCLIVersion = "1.0.0" 82 expectedDoppler = "wss://doppler.foo.com" 83 expectedRouting = "https://api.foo.com/routing" 84 85 settings.URL = expectedAPI 86 87 fakeCloudControllerClient.APIReturns(expectedAPI) 88 fakeCloudControllerClient.APIVersionReturns(expectedAPIVersion) 89 fakeCloudControllerClient.AuthorizationEndpointReturns(expectedAuth) 90 fakeCloudControllerClient.MinCLIVersionReturns(expectedMinCLIVersion) 91 fakeCloudControllerClient.DopplerEndpointReturns(expectedDoppler) 92 fakeCloudControllerClient.RoutingEndpointReturns(expectedRouting) 93 }) 94 95 It("targets the passed API", func() { 96 _, err := actor.SetTarget(settings) 97 Expect(err).ToNot(HaveOccurred()) 98 99 Expect(fakeCloudControllerClient.TargetCFCallCount()).To(Equal(1)) 100 connectionSettings := fakeCloudControllerClient.TargetCFArgsForCall(0) 101 Expect(connectionSettings.URL).To(Equal(expectedAPI)) 102 Expect(connectionSettings.SkipSSLValidation).To(BeFalse()) 103 }) 104 105 It("sets all the target information", func() { 106 _, err := actor.SetTarget(settings) 107 Expect(err).ToNot(HaveOccurred()) 108 109 Expect(fakeConfig.SetTargetInformationCallCount()).To(Equal(1)) 110 api, apiVersion, auth, minCLIVersion, doppler, routing, sslDisabled := fakeConfig.SetTargetInformationArgsForCall(0) 111 112 Expect(api).To(Equal(expectedAPI)) 113 Expect(apiVersion).To(Equal(expectedAPIVersion)) 114 Expect(auth).To(Equal(expectedAuth)) 115 Expect(minCLIVersion).To(Equal(expectedMinCLIVersion)) 116 Expect(doppler).To(Equal(expectedDoppler)) 117 Expect(routing).To(Equal(expectedRouting)) 118 Expect(sslDisabled).To(Equal(skipSSLValidation)) 119 }) 120 121 It("clears all the token information", func() { 122 _, err := actor.SetTarget(settings) 123 Expect(err).ToNot(HaveOccurred()) 124 125 Expect(fakeConfig.SetTokenInformationCallCount()).To(Equal(1)) 126 accessToken, refreshToken, sshOAuthClient := fakeConfig.SetTokenInformationArgsForCall(0) 127 128 Expect(accessToken).To(BeEmpty()) 129 Expect(refreshToken).To(BeEmpty()) 130 Expect(sshOAuthClient).To(BeEmpty()) 131 }) 132 133 When("setting the same API and skip SSL configuration", func() { 134 var APIURL string 135 136 BeforeEach(func() { 137 APIURL = "https://some-api.com" 138 settings.URL = APIURL 139 fakeConfig.TargetReturns(APIURL) 140 fakeConfig.SkipSSLValidationReturns(skipSSLValidation) 141 }) 142 143 It("does not make any API calls", func() { 144 warnings, err := actor.SetTarget(settings) 145 Expect(err).NotTo(HaveOccurred()) 146 Expect(warnings).To(BeNil()) 147 148 Expect(fakeCloudControllerClient.TargetCFCallCount()).To(BeZero()) 149 }) 150 }) 151 }) 152 153 })