github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/command/v6/shared/new_clients_test.go (about) 1 package shared_test 2 3 import ( 4 "net/http" 5 "runtime" 6 "time" 7 8 "code.cloudfoundry.org/cli/command/commandfakes" 9 "code.cloudfoundry.org/cli/command/translatableerror" 10 . "code.cloudfoundry.org/cli/command/v6/shared" 11 "code.cloudfoundry.org/cli/util/ui" 12 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 . "github.com/onsi/gomega/gbytes" 16 . "github.com/onsi/gomega/ghttp" 17 ) 18 19 var _ = Describe("New Clients", func() { 20 var ( 21 binaryName string 22 fakeConfig *commandfakes.FakeConfig 23 testUI *ui.UI 24 ) 25 26 BeforeEach(func() { 27 binaryName = "faceman" 28 fakeConfig = new(commandfakes.FakeConfig) 29 testUI = ui.NewTestUI(NewBuffer(), NewBuffer(), NewBuffer()) 30 31 fakeConfig.BinaryNameReturns(binaryName) 32 }) 33 34 When("the api endpoint is not set", func() { 35 It("returns an error", func() { 36 _, _, err := NewClients(fakeConfig, testUI, true) 37 Expect(err).To(MatchError(translatableerror.NoAPISetError{ 38 BinaryName: binaryName, 39 })) 40 }) 41 }) 42 43 When("the DialTimeout is set", func() { 44 BeforeEach(func() { 45 if runtime.GOOS == "windows" { 46 Skip("due to timing issues on windows") 47 } 48 fakeConfig.TargetReturns("https://potato.bananapants11122.co.uk") 49 fakeConfig.DialTimeoutReturns(time.Nanosecond) 50 }) 51 52 It("passes the value to the target", func() { 53 _, _, err := NewClients(fakeConfig, testUI, true) 54 Expect(err.Error()).To(MatchRegexp("timeout")) 55 }) 56 }) 57 58 When("the targeting a CF fails", func() { 59 BeforeEach(func() { 60 fakeConfig.TargetReturns("https://potato.bananapants11122.co.uk") 61 }) 62 63 It("returns an error", func() { 64 _, _, err := NewClients(fakeConfig, testUI, true) 65 Expect(err).To(HaveOccurred()) 66 }) 67 }) 68 69 When("the targeted CF is older than the minimum supported version", func() { 70 var server *Server 71 72 BeforeEach(func() { 73 server = NewTLSServer() 74 75 fakeConfig.TargetReturns(server.URL()) 76 fakeConfig.SkipSSLValidationReturns(true) 77 server.AppendHandlers( 78 CombineHandlers( 79 VerifyRequest(http.MethodGet, "/v2/info"), 80 RespondWith(http.StatusOK, `{ "api_version": "2.68.0" }`), 81 ), 82 ) 83 }) 84 85 AfterEach(func() { 86 server.Close() 87 }) 88 89 It("outputs a warning", func() { 90 NewClients(fakeConfig, testUI, true) 91 92 Expect(testUI.Err).To(Say("Your API version is no longer supported. Upgrade to a newer version of the API")) 93 }) 94 }) 95 96 When("not targetting", func() { 97 It("does not target and returns no UAA client", func() { 98 ccClient, uaaClient, err := NewClients(fakeConfig, testUI, false) 99 Expect(err).ToNot(HaveOccurred()) 100 Expect(ccClient).ToNot(BeNil()) 101 Expect(uaaClient).To(BeNil()) 102 Expect(fakeConfig.SkipSSLValidationCallCount()).To(Equal(0)) 103 }) 104 }) 105 })