github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/requirements/login_test.go (about)

     1  package requirements_test
     2  
     3  import (
     4  	"github.com/cloudfoundry/cli/cf/configuration/core_config"
     5  	. "github.com/cloudfoundry/cli/cf/requirements"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  
     9  	testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
    10  	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
    11  
    12  	. "github.com/cloudfoundry/cli/testhelpers/matchers"
    13  )
    14  
    15  var _ = Describe("LoginRequirement", func() {
    16  	var ui *testterm.FakeUI
    17  
    18  	BeforeEach(func() {
    19  		ui = new(testterm.FakeUI)
    20  	})
    21  
    22  	It("succeeds when given a config with an API endpoint and authentication", func() {
    23  		config := testconfig.NewRepositoryWithAccessToken(core_config.TokenInfo{Username: "my-user"})
    24  		config.SetApiEndpoint("api.example.com")
    25  		req := NewLoginRequirement(ui, config)
    26  		success := req.Execute()
    27  		Expect(success).To(BeTrue())
    28  	})
    29  
    30  	It("fails when given a config with only an API endpoint", func() {
    31  		config := testconfig.NewRepository()
    32  		config.SetApiEndpoint("api.example.com")
    33  		req := NewLoginRequirement(ui, config)
    34  		success := req.Execute()
    35  		Expect(success).To(BeFalse())
    36  
    37  		Expect(ui.Outputs).To(ContainSubstrings([]string{"Not logged in."}))
    38  	})
    39  
    40  	It("fails when given a config with neither an API endpoint nor authentication", func() {
    41  		config := testconfig.NewRepository()
    42  		req := NewLoginRequirement(ui, config)
    43  		success := req.Execute()
    44  		Expect(success).To(BeFalse())
    45  
    46  		Expect(ui.Outputs).To(ContainSubstrings([]string{"No API endpoint"}))
    47  		Expect(ui.Outputs).ToNot(ContainSubstrings([]string{"Not logged in."}))
    48  	})
    49  })