github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/cf/requirements/login_test.go (about) 1 package requirements_test 2 3 import ( 4 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 5 . "code.cloudfoundry.org/cli/cf/requirements" 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 9 testconfig "code.cloudfoundry.org/cli/util/testhelpers/configuration" 10 ) 11 12 var _ = Describe("LoginRequirement", func() { 13 BeforeEach(func() { 14 }) 15 16 It("succeeds when given a config with an API endpoint and authentication", func() { 17 config := testconfig.NewRepositoryWithAccessToken(coreconfig.TokenInfo{Username: "my-user"}) 18 config.SetAPIEndpoint("api.example.com") 19 req := NewLoginRequirement(config) 20 err := req.Execute() 21 Expect(err).NotTo(HaveOccurred()) 22 }) 23 24 It("fails when given a config with only an API endpoint", func() { 25 config := testconfig.NewRepository() 26 config.SetAPIEndpoint("api.example.com") 27 req := NewLoginRequirement(config) 28 err := req.Execute() 29 Expect(err).To(HaveOccurred()) 30 31 Expect(err.Error()).To(ContainSubstring("Not logged in.")) 32 }) 33 34 It("fails when given a config with neither an API endpoint nor authentication", func() { 35 config := testconfig.NewRepository() 36 req := NewLoginRequirement(config) 37 err := req.Execute() 38 Expect(err).To(HaveOccurred()) 39 40 Expect(err.Error()).To(ContainSubstring("No API endpoint")) 41 Expect(err.Error()).ToNot(ContainSubstring("Not logged in.")) 42 }) 43 })