github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+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) 25 26 settings = TargetSettings{ 27 SkipSSLValidation: skipSSLValidation, 28 } 29 }) 30 31 Describe("SetTarget", func() { 32 var expectedAPI, expectedAPIVersion, expectedAuth, expectedMinCLIVersion, expectedDoppler, expectedUAA, expectedRouting string 33 34 BeforeEach(func() { 35 expectedAPI = "https://api.foo.com" 36 expectedAPIVersion = "2.59.0" 37 expectedAuth = "https://login.foo.com" 38 expectedMinCLIVersion = "1.0.0" 39 expectedDoppler = "wss://doppler.foo.com" 40 expectedUAA = "https://uaa.foo.com" 41 expectedRouting = "https://api.foo.com/routing" 42 43 settings.URL = expectedAPI 44 45 fakeCloudControllerClient.APIReturns(expectedAPI) 46 fakeCloudControllerClient.APIVersionReturns(expectedAPIVersion) 47 fakeCloudControllerClient.AuthorizationEndpointReturns(expectedAuth) 48 fakeCloudControllerClient.MinCLIVersionReturns(expectedMinCLIVersion) 49 fakeCloudControllerClient.DopplerEndpointReturns(expectedDoppler) 50 fakeCloudControllerClient.TokenEndpointReturns(expectedUAA) 51 fakeCloudControllerClient.RoutingEndpointReturns(expectedRouting) 52 }) 53 54 It("targets the passed API", func() { 55 _, err := actor.SetTarget(fakeConfig, settings) 56 Expect(err).ToNot(HaveOccurred()) 57 58 Expect(fakeCloudControllerClient.TargetCFCallCount()).To(Equal(1)) 59 connectionSettings := fakeCloudControllerClient.TargetCFArgsForCall(0) 60 Expect(connectionSettings.URL).To(Equal(expectedAPI)) 61 Expect(connectionSettings.SkipSSLValidation).To(BeFalse()) 62 }) 63 64 It("sets all the target information", func() { 65 _, err := actor.SetTarget(fakeConfig, settings) 66 Expect(err).ToNot(HaveOccurred()) 67 68 Expect(fakeConfig.SetTargetInformationCallCount()).To(Equal(1)) 69 api, apiVersion, auth, minCLIVersion, doppler, uaa, routing, sslDisabled := fakeConfig.SetTargetInformationArgsForCall(0) 70 71 Expect(api).To(Equal(expectedAPI)) 72 Expect(apiVersion).To(Equal(expectedAPIVersion)) 73 Expect(auth).To(Equal(expectedAuth)) 74 Expect(minCLIVersion).To(Equal(expectedMinCLIVersion)) 75 Expect(doppler).To(Equal(expectedDoppler)) 76 Expect(uaa).To(Equal(expectedUAA)) 77 Expect(routing).To(Equal(expectedRouting)) 78 Expect(sslDisabled).To(Equal(skipSSLValidation)) 79 }) 80 81 It("clears all the token information", func() { 82 _, err := actor.SetTarget(fakeConfig, settings) 83 Expect(err).ToNot(HaveOccurred()) 84 85 Expect(fakeConfig.SetTokenInformationCallCount()).To(Equal(1)) 86 accessToken, refreshToken, sshOAuthClient := fakeConfig.SetTokenInformationArgsForCall(0) 87 88 Expect(accessToken).To(BeEmpty()) 89 Expect(refreshToken).To(BeEmpty()) 90 Expect(sshOAuthClient).To(BeEmpty()) 91 }) 92 93 Context("when setting the same API and skip SSL configuration", func() { 94 var APIURL string 95 96 BeforeEach(func() { 97 APIURL = "https://some-api.com" 98 settings.URL = APIURL 99 fakeConfig.TargetReturns(APIURL) 100 fakeConfig.SkipSSLValidationReturns(skipSSLValidation) 101 }) 102 103 It("does not make any API calls", func() { 104 warnings, err := actor.SetTarget(fakeConfig, settings) 105 Expect(err).NotTo(HaveOccurred()) 106 Expect(warnings).To(BeNil()) 107 108 Expect(fakeCloudControllerClient.TargetCFCallCount()).To(BeZero()) 109 }) 110 }) 111 }) 112 113 Describe("ClearTarget", func() { 114 It("clears all the target information", func() { 115 actor.ClearTarget(fakeConfig) 116 117 Expect(fakeConfig.SetTargetInformationCallCount()).To(Equal(1)) 118 api, apiVersion, auth, minCLIVersion, doppler, uaa, routing, sslDisabled := fakeConfig.SetTargetInformationArgsForCall(0) 119 120 Expect(api).To(BeEmpty()) 121 Expect(apiVersion).To(BeEmpty()) 122 Expect(auth).To(BeEmpty()) 123 Expect(minCLIVersion).To(BeEmpty()) 124 Expect(doppler).To(BeEmpty()) 125 Expect(uaa).To(BeEmpty()) 126 Expect(routing).To(BeEmpty()) 127 Expect(sslDisabled).To(BeFalse()) 128 }) 129 130 It("clears all the token information", func() { 131 actor.ClearTarget(fakeConfig) 132 133 Expect(fakeConfig.SetTokenInformationCallCount()).To(Equal(1)) 134 accessToken, refreshToken, sshOAuthClient := fakeConfig.SetTokenInformationArgsForCall(0) 135 136 Expect(accessToken).To(BeEmpty()) 137 Expect(refreshToken).To(BeEmpty()) 138 Expect(sshOAuthClient).To(BeEmpty()) 139 }) 140 }) 141 142 Describe("ClearOrganizationAndSpace", func() { 143 It("clears all organization and space information", func() { 144 actor.ClearOrganizationAndSpace(fakeConfig) 145 146 Expect(fakeConfig.UnsetOrganizationInformationCallCount()).To(Equal(1)) 147 Expect(fakeConfig.UnsetSpaceInformationCallCount()).To(Equal(1)) 148 }) 149 }) 150 })