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