github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/orgs_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  	. "github.com/onsi/gomega/gbytes"
     8  	. "github.com/onsi/gomega/gexec"
     9  )
    10  
    11  var _ = Describe("orgs command", func() {
    12  	Describe("help", func() {
    13  		Context("when --help flag is set", func() {
    14  			It("displays command usage to output", func() {
    15  				session := helpers.CF("orgs", "--help")
    16  				Eventually(session).Should(Say("NAME:"))
    17  				Eventually(session).Should(Say("\\s+orgs - List all orgs"))
    18  				Eventually(session).Should(Say("USAGE:"))
    19  				Eventually(session).Should(Say("\\s+cf orgs"))
    20  				Eventually(session).Should(Say("ALIAS:"))
    21  				Eventually(session).Should(Say("\\s+o"))
    22  				Eventually(session).Should(Exit(0))
    23  			})
    24  		})
    25  	})
    26  
    27  	Context("when the environment is not setup correctly", func() {
    28  		Context("when an API endpoint is not set", func() {
    29  			BeforeEach(func() {
    30  				helpers.UnsetAPI()
    31  			})
    32  
    33  			It("displays an error and exits 1", func() {
    34  				session := helpers.CF("orgs")
    35  				Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\."))
    36  				Eventually(session).Should(Say("FAILED"))
    37  				Eventually(session).Should(Exit(1))
    38  			})
    39  		})
    40  
    41  		Context("when an API endpoint is set", func() {
    42  			Context("when the user is not logged in", func() {
    43  				It("displays an error and exits 1", func() {
    44  					session := helpers.CF("orgs")
    45  					Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\."))
    46  					Eventually(session).Should(Say("FAILED"))
    47  					Eventually(session).Should(Exit(1))
    48  				})
    49  			})
    50  		})
    51  	})
    52  
    53  	Context("when the environment is setup correctly", func() {
    54  		var username string
    55  
    56  		BeforeEach(func() {
    57  			username = helpers.LoginCF()
    58  		})
    59  
    60  		// This test is skipped because we have remaining manual orgs that we do
    61  		// not want to remove. We can unskip this test when we create a dev
    62  		// environment for our manual testing in this story: #151187003
    63  		PContext("when there are no orgs", func() {
    64  			It("displays no orgs found", func() {
    65  				session := helpers.CF("orgs")
    66  				Eventually(session).Should(Say("Getting orgs as %s\\.\\.\\.", username))
    67  				Eventually(session).Should(Say(""))
    68  				Eventually(session).Should(Say("No orgs found\\."))
    69  				Eventually(session).Should(Exit(0))
    70  			})
    71  		})
    72  
    73  		Context("when there are multiple orgs", func() {
    74  			var orgName1, orgName2, orgName3, orgName4, orgName5 string
    75  
    76  			BeforeEach(func() {
    77  				orgName1 = helpers.PrefixedRandomName("INTEGRATION-ORG-XYZ")
    78  				orgName2 = helpers.PrefixedRandomName("INTEGRATION-ORG-123")
    79  				orgName3 = helpers.PrefixedRandomName("INTEGRATION-ORG-ABC")
    80  				orgName4 = helpers.PrefixedRandomName("INTEGRATION-ORG---")
    81  				orgName5 = helpers.PrefixedRandomName("INTEGRATION-ORG-ghi")
    82  				helpers.CreateOrg(orgName1)
    83  				helpers.CreateOrg(orgName2)
    84  				helpers.CreateOrg(orgName3)
    85  				helpers.CreateOrg(orgName4)
    86  				helpers.CreateOrg(orgName5)
    87  			})
    88  
    89  			AfterEach(func() {
    90  				helpers.QuickDeleteOrg(orgName1)
    91  				helpers.QuickDeleteOrg(orgName2)
    92  				helpers.QuickDeleteOrg(orgName3)
    93  				helpers.QuickDeleteOrg(orgName4)
    94  				helpers.QuickDeleteOrg(orgName5)
    95  			})
    96  
    97  			It("displays a list of all orgs", func() {
    98  				session := helpers.CF("orgs")
    99  				Eventually(session).Should(Say("Getting orgs as %s\\.\\.\\.", username))
   100  				Eventually(session).Should(Say(""))
   101  				Eventually(session).Should(Say("name"))
   102  				Eventually(session).Should(Say("%s", orgName4))
   103  				Eventually(session).Should(Say("%s", orgName2))
   104  				Eventually(session).Should(Say("%s", orgName3))
   105  				Eventually(session).Should(Say("%s", orgName5))
   106  				Eventually(session).Should(Say("%s", orgName1))
   107  				Eventually(session).Should(Exit(0))
   108  			})
   109  		})
   110  	})
   111  })