github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/logout_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  	"code.cloudfoundry.org/cli/util/configv3"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("logout command", func() {
    13  	Context("help", func() {
    14  		It("displays help", func() {
    15  			session := helpers.CF("logout", "--help")
    16  			Eventually(session).Should(Say("NAME:"))
    17  			Eventually(session).Should(Say("   logout - Log user out"))
    18  			Eventually(session).Should(Say("USAGE:"))
    19  			Eventually(session).Should(Say("   cf logout"))
    20  			Eventually(session).Should(Say("ALIAS:"))
    21  			Eventually(session).Should(Say("   lo"))
    22  			Eventually(session).Should(Exit(0))
    23  		})
    24  	})
    25  
    26  	When("there's user information set in the config", func() {
    27  		BeforeEach(func() {
    28  			helpers.SetupCF(ReadOnlyOrg, ReadOnlySpace)
    29  		})
    30  
    31  		It("clears out user information in the config", func() {
    32  			username, _ := helpers.GetCredentials()
    33  			session := helpers.CF("logout")
    34  
    35  			Eventually(session).Should(Say(`Logging out %s\.\.\.`, username))
    36  			Eventually(session).Should(Say("OK"))
    37  			Eventually(session).Should(Exit(0))
    38  
    39  			config, err := configv3.LoadConfig()
    40  			Expect(err).ToNot(HaveOccurred())
    41  
    42  			Expect(config.ConfigFile.AccessToken).To(BeEmpty())
    43  			Expect(config.ConfigFile.RefreshToken).To(BeEmpty())
    44  			Expect(config.ConfigFile.TargetedOrganization.GUID).To(BeEmpty())
    45  			Expect(config.ConfigFile.TargetedOrganization.Name).To(BeEmpty())
    46  			Expect(config.ConfigFile.TargetedSpace.AllowSSH).To(BeFalse())
    47  			Expect(config.ConfigFile.TargetedSpace.GUID).To(BeEmpty())
    48  			Expect(config.ConfigFile.TargetedSpace.Name).To(BeEmpty())
    49  			Expect(config.ConfigFile.UAAGrantType).To(BeEmpty())
    50  			Expect(config.ConfigFile.UAAOAuthClient).To(Equal("cf"))
    51  			Expect(config.ConfigFile.UAAOAuthClientSecret).To(BeEmpty())
    52  
    53  			session = helpers.CF("orgs")
    54  			Eventually(session).Should(Exit(1))
    55  			Expect(session.Out).To(Say("FAILED"))
    56  			Expect(session.Err).To(Say("Not logged in."))
    57  		})
    58  	})
    59  })