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