github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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  		It("fails with the appropriate errors", func() {
    38  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "enable-org-isolation", "org-name", "segment-name")
    39  		})
    40  
    41  		Context("when the v3 api does not exist", func() {
    42  			var server *Server
    43  
    44  			BeforeEach(func() {
    45  				server = helpers.StartAndTargetServerWithoutV3API()
    46  			})
    47  
    48  			AfterEach(func() {
    49  				server.Close()
    50  			})
    51  
    52  			It("fails with error message that the minimum version is not met", func() {
    53  				session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
    54  				Eventually(session).Should(Say("FAILED"))
    55  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\."))
    56  				Eventually(session).Should(Exit(1))
    57  			})
    58  		})
    59  
    60  		Context("when the v3 api version is lower than the minimum version", func() {
    61  			var server *Server
    62  
    63  			BeforeEach(func() {
    64  				server = helpers.StartAndTargetServerWithV3Version("3.0.0")
    65  			})
    66  
    67  			AfterEach(func() {
    68  				server.Close()
    69  			})
    70  
    71  			It("fails with error message that the minimum version is not met", func() {
    72  				session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
    73  				Eventually(session).Should(Say("FAILED"))
    74  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\."))
    75  				Eventually(session).Should(Exit(1))
    76  			})
    77  		})
    78  	})
    79  
    80  	Context("when the environment is set up correctly", func() {
    81  		var userName string
    82  
    83  		BeforeEach(func() {
    84  			helpers.LoginCF()
    85  			userName, _ = helpers.GetCredentials()
    86  		})
    87  
    88  		Context("when the isolation segment does not exist", func() {
    89  			It("fails with isolation segment not found message", func() {
    90  				session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
    91  				Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName))
    92  				Eventually(session).Should(Say("FAILED"))
    93  				Eventually(session.Err).Should(Say("Isolation segment '%s' not found.", isolationSegmentName))
    94  				Eventually(session).Should(Exit(1))
    95  			})
    96  		})
    97  
    98  		Context("when the isolation segment exists", func() {
    99  			BeforeEach(func() {
   100  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   101  			})
   102  
   103  			Context("when the organization does not exist", func() {
   104  				It("fails with organization not found message", func() {
   105  					session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
   106  					Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName))
   107  					Eventually(session).Should(Say("FAILED"))
   108  					Eventually(session.Err).Should(Say("Organization '%s' not found.", organizationName))
   109  					Eventually(session).Should(Exit(1))
   110  				})
   111  			})
   112  
   113  			Context("when the organization exists", func() {
   114  				BeforeEach(func() {
   115  					helpers.CreateOrg(organizationName)
   116  					helpers.TargetOrg(organizationName)
   117  				})
   118  
   119  				AfterEach(func() {
   120  					helpers.QuickDeleteOrg(organizationName)
   121  				})
   122  
   123  				It("displays OK", func() {
   124  					session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
   125  					Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName))
   126  					Eventually(session).Should(Say("OK"))
   127  					Eventually(session).Should(Exit(0))
   128  				})
   129  
   130  				Context("when the isolation is already enabled", func() {
   131  					BeforeEach(func() {
   132  						Eventually(helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)).Should(Exit(0))
   133  					})
   134  
   135  					It("displays OK", func() {
   136  						session := helpers.CF("enable-org-isolation", organizationName, isolationSegmentName)
   137  						Eventually(session).Should(Say("Enabling isolation segment %s for org %s as %s...", isolationSegmentName, organizationName, userName))
   138  						Eventually(session).Should(Say("OK"))
   139  						Eventually(session).Should(Exit(0))
   140  					})
   141  				})
   142  			})
   143  		})
   144  	})
   145  })