github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/v7/shared/new_clients_test.go (about)

     1  package shared_test
     2  
     3  import (
     4  	"runtime"
     5  	"time"
     6  
     7  	"github.com/LukasHeimann/cloudfoundrycli/v8/command/commandfakes"
     8  	"github.com/LukasHeimann/cloudfoundrycli/v8/command/translatableerror"
     9  	. "github.com/LukasHeimann/cloudfoundrycli/v8/command/v7/shared"
    10  	"github.com/LukasHeimann/cloudfoundrycli/v8/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  		fakeConfig.BinaryNameReturns(binaryName)
    28  
    29  		testUI = ui.NewTestUI(NewBuffer(), NewBuffer(), NewBuffer())
    30  	})
    31  
    32  	When("the api endpoint is not set", func() {
    33  		It("returns the NoAPISetError", func() {
    34  			_, _, _, err := GetNewClientsAndConnectToCF(fakeConfig, testUI, "")
    35  			Expect(err).To(MatchError(translatableerror.NoAPISetError{
    36  				BinaryName: binaryName,
    37  			}))
    38  		})
    39  	})
    40  
    41  	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("reads target settings from the config for each client", func() {
    51  			_, _, _, err := GetNewClientsAndConnectToCF(fakeConfig, testUI, "")
    52  
    53  			Expect(err).NotTo(HaveOccurred())
    54  			Expect(fakeConfig.TargetCallCount()).To(Equal(2))
    55  			Expect(fakeConfig.DialTimeoutCallCount()).To(Equal(3))
    56  			Expect(fakeConfig.SkipSSLValidationCallCount()).To(Equal(3))
    57  		})
    58  	})
    59  
    60  	When("not targetting", func() {
    61  		It("does not target", func() {
    62  			ccClient := NewWrappedCloudControllerClient(fakeConfig, testUI)
    63  			Expect(ccClient).ToNot(BeNil())
    64  			Expect(fakeConfig.SkipSSLValidationCallCount()).To(Equal(0))
    65  		})
    66  	})
    67  })