github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+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, true)
    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, true)
    52  			Expect(err.Error()).To(MatchRegexp("TIP: If you are behind a firewall"))
    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, true)
    63  			Expect(err).To(HaveOccurred())
    64  		})
    65  	})
    66  
    67  	Context("when not targetting", func() {
    68  		It("does not target and returns no UAA client", func() {
    69  			ccClient, uaaClient, err := NewClients(fakeConfig, testUI, false)
    70  			Expect(err).ToNot(HaveOccurred())
    71  			Expect(ccClient).ToNot(BeNil())
    72  			Expect(uaaClient).To(BeNil())
    73  			Expect(fakeConfig.SkipSSLValidationCallCount()).To(Equal(0))
    74  		})
    75  	})
    76  })