github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/isolation_segments_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  	. "github.com/onsi/gomega/ghttp"
    10  )
    11  
    12  var _ = Describe("isolation-segments command", func() {
    13  	Describe("help", func() {
    14  		Context("when --help flag is set", func() {
    15  			It("Displays command usage to output", func() {
    16  				session := helpers.CF("isolation-segments", "--help")
    17  				Eventually(session).Should(Say("NAME:"))
    18  				Eventually(session).Should(Say("isolation-segments - List all isolation segments"))
    19  				Eventually(session).Should(Say("USAGE:"))
    20  				Eventually(session).Should(Say("cf isolation-segments"))
    21  				Eventually(session).Should(Say("SEE ALSO:"))
    22  				Eventually(session).Should(Say("create-isolation-segment, enable-org-isolation"))
    23  				Eventually(session).Should(Exit(0))
    24  			})
    25  		})
    26  	})
    27  
    28  	Context("when the environment is not setup correctly", func() {
    29  		Context("when no API endpoint is set", func() {
    30  			BeforeEach(func() {
    31  				helpers.UnsetAPI()
    32  			})
    33  
    34  			It("fails with no API endpoint set message", func() {
    35  				session := helpers.CF("isolation-segments")
    36  				Eventually(session).Should(Say("FAILED"))
    37  				Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint."))
    38  				Eventually(session).Should(Exit(1))
    39  			})
    40  		})
    41  
    42  		Context("when the v3 api does not exist", func() {
    43  			var server *Server
    44  
    45  			BeforeEach(func() {
    46  				server = helpers.StartAndTargetServerWithoutV3API()
    47  			})
    48  
    49  			AfterEach(func() {
    50  				server.Close()
    51  			})
    52  
    53  			It("fails with error message that the minimum version is not met", func() {
    54  				session := helpers.CF("isolation-segments")
    55  				Eventually(session).Should(Say("FAILED"))
    56  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\."))
    57  				Eventually(session).Should(Exit(1))
    58  			})
    59  		})
    60  
    61  		Context("when the v3 api version is lower than the minimum version", func() {
    62  			var server *Server
    63  
    64  			BeforeEach(func() {
    65  				server = helpers.StartAndTargetServerWithV3Version("3.0.0")
    66  			})
    67  
    68  			AfterEach(func() {
    69  				server.Close()
    70  			})
    71  
    72  			It("fails with error message that the minimum version is not met", func() {
    73  				session := helpers.CF("isolation-segments")
    74  				Eventually(session).Should(Say("FAILED"))
    75  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\."))
    76  				Eventually(session).Should(Exit(1))
    77  			})
    78  		})
    79  
    80  		Context("when not logged in", func() {
    81  			BeforeEach(func() {
    82  				helpers.LogoutCF()
    83  			})
    84  
    85  			It("fails with not logged in message", func() {
    86  				session := helpers.CF("isolation-segments")
    87  				Eventually(session).Should(Say("FAILED"))
    88  				Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in."))
    89  				Eventually(session).Should(Exit(1))
    90  			})
    91  		})
    92  	})
    93  
    94  	Context("when the environment is set up correctly", func() {
    95  		BeforeEach(func() {
    96  			helpers.LoginCF()
    97  		})
    98  
    99  		Context("when there are some isolation segments", func() {
   100  			var isolationSegment1 string // No orgs assigned
   101  			var isolationSegment2 string // One org assigned
   102  			var isolationSegment3 string // Many orgs assigned
   103  			var org1 string
   104  			var org2 string
   105  
   106  			BeforeEach(func() {
   107  				org1 = helpers.NewOrgName()
   108  				org2 = helpers.NewOrgName()
   109  				helpers.CreateOrg(org1)
   110  				helpers.CreateOrg(org2)
   111  
   112  				isolationSegment1 = helpers.NewIsolationSegmentName()
   113  				isolationSegment2 = helpers.NewIsolationSegmentName()
   114  				isolationSegment3 = helpers.NewIsolationSegmentName()
   115  
   116  				Eventually(helpers.CF("create-isolation-segment", isolationSegment1)).Should(Exit(0))
   117  				Eventually(helpers.CF("create-isolation-segment", isolationSegment2)).Should(Exit(0))
   118  				Eventually(helpers.CF("create-isolation-segment", isolationSegment3)).Should(Exit(0))
   119  				Eventually(helpers.CF("enable-org-isolation", org1, isolationSegment2)).Should(Exit(0))
   120  				Eventually(helpers.CF("enable-org-isolation", org1, isolationSegment3)).Should(Exit(0))
   121  				Eventually(helpers.CF("enable-org-isolation", org2, isolationSegment3)).Should(Exit(0))
   122  			})
   123  
   124  			AfterEach(func() {
   125  				helpers.QuickDeleteOrg(org1)
   126  				helpers.QuickDeleteOrg(org2)
   127  			})
   128  
   129  			It("returns an ok and displays the table", func() {
   130  				userName, _ := helpers.GetCredentials()
   131  				session := helpers.CF("isolation-segments")
   132  				Eventually(session).Should(Say("Getting isolation segments as %s...", userName))
   133  				Eventually(session).Should(Say("OK"))
   134  				Eventually(session).Should(Say("name\\s+orgs"))
   135  				Eventually(session).Should(Say("shared"))
   136  				Eventually(session).Should(Say("%s\\s+", isolationSegment1))
   137  				Eventually(session).Should(Say("%s\\s+%s", isolationSegment2, org1))
   138  				Eventually(session).Should(Say("%s\\s+%s, %s", isolationSegment3, org1, org2))
   139  				Eventually(session).Should(Exit(0))
   140  			})
   141  		})
   142  	})
   143  })