github.com/niteshexa/cloudfoundry_cli@v7.1.0+incompatible/command/v7/logout_command_test.go (about)

     1  package v7_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/uaa"
     5  	"code.cloudfoundry.org/cli/command/commandfakes"
     6  	. "code.cloudfoundry.org/cli/command/v7"
     7  	"code.cloudfoundry.org/cli/command/v7/v7fakes"
     8  	"code.cloudfoundry.org/cli/util/configv3"
     9  	"code.cloudfoundry.org/cli/util/ui"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  )
    14  
    15  var _ = Describe("logout command", func() {
    16  	var (
    17  		cmd        LogoutCommand
    18  		testUI     *ui.UI
    19  		fakeConfig *commandfakes.FakeConfig
    20  		fakeActor  *v7fakes.FakeActor
    21  		executeErr error
    22  	)
    23  
    24  	BeforeEach(func() {
    25  		testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer())
    26  		fakeConfig = new(commandfakes.FakeConfig)
    27  		fakeActor = new(v7fakes.FakeActor)
    28  		cmd = LogoutCommand{
    29  			BaseCommand: BaseCommand{
    30  				UI:     testUI,
    31  				Config: fakeConfig,
    32  				Actor:  fakeActor,
    33  			},
    34  		}
    35  
    36  		fakeConfig.CurrentUserReturns(
    37  			configv3.User{
    38  				Name: "some-user",
    39  			},
    40  			nil)
    41  	})
    42  
    43  	JustBeforeEach(func() {
    44  		executeErr = cmd.Execute(nil)
    45  	})
    46  
    47  	It("outputs logging out display message", func() {
    48  		Expect(executeErr).ToNot(HaveOccurred())
    49  
    50  		Expect(fakeConfig.UnsetUserInformationCallCount()).To(Equal(1))
    51  		Expect(testUI.Out).To(Say("Logging out some-user..."))
    52  		Expect(testUI.Out).To(Say("OK"))
    53  	})
    54  
    55  	It("calls to revoke the auth tokens", func() {
    56  		Expect(fakeActor.RevokeAccessAndRefreshTokensCallCount()).To(Equal(1))
    57  	})
    58  
    59  	When("The revoking of tokens fails", func() {
    60  		BeforeEach(func() {
    61  			fakeActor.RevokeAccessAndRefreshTokensReturns(error(uaa.UnauthorizedError{Message: "test error"}))
    62  		})
    63  
    64  		It("does not impact the logout", func() {
    65  			Expect(executeErr).ToNot(HaveOccurred())
    66  			Expect(fakeConfig.UnsetUserInformationCallCount()).To(Equal(1))
    67  			Expect(testUI.Out).To(Say("Logging out some-user..."))
    68  			Expect(testUI.Out).To(Say("OK"))
    69  		})
    70  	})
    71  })