github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/command/v2/shared/new_clients_test.go (about) 1 package shared_test 2 3 import ( 4 "runtime" 5 "time" 6 7 "code.cloudfoundry.org/cli/command" 8 "code.cloudfoundry.org/cli/command/commandfakes" 9 . "code.cloudfoundry.org/cli/command/v2/shared" 10 "code.cloudfoundry.org/cli/util/ui" 11 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 . "github.com/onsi/gomega/gbytes" 15 ) 16 17 var _ = Describe("New Clients", func() { 18 var ( 19 binaryName string 20 fakeConfig *commandfakes.FakeConfig 21 testUI *ui.UI 22 ) 23 24 BeforeEach(func() { 25 binaryName = "faceman" 26 fakeConfig = new(commandfakes.FakeConfig) 27 testUI = ui.NewTestUI(NewBuffer(), NewBuffer(), NewBuffer()) 28 29 fakeConfig.BinaryNameReturns(binaryName) 30 }) 31 32 Context("when the api endpoint is not set", func() { 33 It("returns an error", func() { 34 _, _, err := NewClients(fakeConfig, testUI) 35 Expect(err).To(MatchError(command.NoAPISetError{ 36 BinaryName: binaryName, 37 })) 38 }) 39 }) 40 41 Context("when the DialTimeout is set", func() { 42 BeforeEach(func() { 43 if runtime.GOOS == "windows" { 44 Skip("due to timing issues on windows") 45 } 46 fakeConfig.TargetReturns("https://potato.bananapants11122.co.uk") 47 fakeConfig.DialTimeoutReturns(time.Nanosecond) 48 }) 49 50 It("passes the value to the target", func() { 51 _, _, err := NewClients(fakeConfig, testUI) 52 Expect(err).To(MatchError("Get https://potato.bananapants11122.co.uk/v2/info: dial tcp: i/o timeout")) 53 }) 54 }) 55 56 Context("when the targeting a CF fails", func() { 57 BeforeEach(func() { 58 fakeConfig.TargetReturns("https://potato.bananapants11122.co.uk") 59 }) 60 61 It("returns an error", func() { 62 _, _, err := NewClients(fakeConfig, testUI) 63 Expect(err).To(HaveOccurred()) 64 }) 65 }) 66 })