github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/enable_org_isolation_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("enable-org-isolation command", func() {
    13  	var organizationName string
    14  	var isolationSegmentName string
    15  
    16  	BeforeEach(func() {
    17  		organizationName = helpers.NewOrgName()
    18  		isolationSegmentName = helpers.NewIsolationSegmentName()
    19  	})
    20  
    21  	Describe("help", func() {
    22  		Context("when --help flag is set", func() {
    23  			It("Displays command usage to output", func() {
    24  				session := helpers.CF("enable-org-isolation", "--help")
    25  				Eventually(session).Should(Say("NAME:"))
    26  				Eventually(session).Should(Say("enable-org-isolation - Entitle an organization to an isolation segment"))
    27  				Eventually(session).Should(Say("USAGE:"))
    28  				Eventually(session).Should(Say("cf enable-org-isolation ORG_NAME SEGMENT_NAME"))
    29  				Eventually(session).Should(Say("SEE ALSO:"))
    30  				Eventually(session).Should(Say("create-isolation-segment, isolation-segments, set-org-default-isolation-segment, set-space-isolation-segment"))
    31  				Eventually(session).Should(Exit(0))
    32  			})
    33  		})
    34  	})
    35  
    36  	Context("when the environment is not setup correctly", func() {
    37  		Context("when no API endpoint is set", func() {
    38  			BeforeEach(func() {
    39  				helpers.UnsetAPI()
    40  			})
    41  
    42  			It("fails with no API endpoint set message", func() {
    43  				session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
    44  				Eventually(session).Should(Say("FAILED"))
    45  				Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint."))
    46  				Eventually(session).Should(Exit(1))
    47  			})
    48  		})
    49  
    50  		Context("when the v3 api does not exist", func() {
    51  			var server *Server
    52  
    53  			BeforeEach(func() {
    54  				server = helpers.StartAndTargetServerWithoutV3API()
    55  			})
    56  
    57  			AfterEach(func() {
    58  				server.Close()
    59  			})
    60  
    61  			It("fails with error message that the minimum version is not met", func() {
    62  				session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
    63  				Eventually(session).Should(Say("FAILED"))
    64  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\."))
    65  				Eventually(session).Should(Exit(1))
    66  			})
    67  		})
    68  
    69  		Context("when the v3 api version is lower than the minimum version", func() {
    70  			var server *Server
    71  
    72  			BeforeEach(func() {
    73  				server = helpers.StartAndTargetServerWithV3Version("3.0.0")
    74  			})
    75  
    76  			AfterEach(func() {
    77  				server.Close()
    78  			})
    79  
    80  			It("fails with error message that the minimum version is not met", func() {
    81  				session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
    82  				Eventually(session).Should(Say("FAILED"))
    83  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\."))
    84  				Eventually(session).Should(Exit(1))
    85  			})
    86  		})
    87  
    88  		Context("when not logged in", func() {
    89  			BeforeEach(func() {
    90  				helpers.LogoutCF()
    91  			})
    92  
    93  			It("fails with not logged in message", func() {
    94  				session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
    95  				Eventually(session).Should(Say("FAILED"))
    96  				Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in."))
    97  				Eventually(session).Should(Exit(1))
    98  			})
    99  		})
   100  	})
   101  
   102  	Context("when the environment is set up correctly", func() {
   103  		var userName string
   104  
   105  		BeforeEach(func() {
   106  			helpers.LoginCF()
   107  			userName, _ = helpers.GetCredentials()
   108  		})
   109  
   110  		Context("when the isolation segment does not exist", func() {
   111  			It("fails with isolation segment not found message", func() {
   112  				session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
   113  				Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName))
   114  				Eventually(session).Should(Say("FAILED"))
   115  				Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName))
   116  				Eventually(session).Should(Exit(1))
   117  			})
   118  		})
   119  
   120  		Context("when the isolation segment exists", func() {
   121  			BeforeEach(func() {
   122  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   123  			})
   124  
   125  			Context("when the organization does not exist", func() {
   126  				It("fails with organization not found message", func() {
   127  					session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
   128  					Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName))
   129  					Eventually(session).Should(Say("FAILED"))
   130  					Eventually(session.Err).Should(Say("Organization '%s' not found.", organizationName))
   131  					Eventually(session).Should(Exit(1))
   132  				})
   133  			})
   134  
   135  			Context("when the organization exists", func() {
   136  				BeforeEach(func() {
   137  					helpers.CreateOrg(organizationName)
   138  					helpers.TargetOrg(organizationName)
   139  				})
   140  
   141  				AfterEach(func() {
   142  					helpers.QuickDeleteOrg(organizationName)
   143  				})
   144  
   145  				It("displays OK", func() {
   146  					session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
   147  					Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName))
   148  					Eventually(session).Should(Say("OK"))
   149  					Eventually(session).Should(Exit(0))
   150  				})
   151  
   152  				Context("when the isolation is already enabled", func() {
   153  					BeforeEach(func() {
   154  						Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0))
   155  					})
   156  
   157  					It("displays OK", func() {
   158  						session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
   159  						Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName))
   160  						Eventually(session).Should(Say("OK"))
   161  						Eventually(session).Should(Exit(0))
   162  					})
   163  				})
   164  			})
   165  		})
   166  	})
   167  })