github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/create_isolation_segment_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("create-isolation-segment command", func() {
    13  	var isolationSegmentName string
    14  
    15  	BeforeEach(func() {
    16  		isolationSegmentName = helpers.NewIsolationSegmentName()
    17  	})
    18  
    19  	Describe("help", func() {
    20  		Context("when --help flag is set", func() {
    21  			It("Displays command usage to output", func() {
    22  				session := helpers.CF("create-isolation-segment", "--help")
    23  				Eventually(session).Should(Say("NAME:"))
    24  				Eventually(session).Should(Say("create-isolation-segment - Create an isolation segment"))
    25  				Eventually(session).Should(Say("USAGE:"))
    26  				Eventually(session).Should(Say("cf create-isolation-segment SEGMENT_NAME"))
    27  				Eventually(session).Should(Say("NOTES:"))
    28  				Eventually(session).Should(Say("The isolation segment name must match the placement tag applied to the Diego cell."))
    29  				Eventually(session).Should(Say("SEE ALSO:"))
    30  				Eventually(session).Should(Say("enable-org-isolation, isolation-segments"))
    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("create-isolation-segment", 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("create-isolation-segment", 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("create-isolation-segment", 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("create-isolation-segment", 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  		BeforeEach(func() {
   104  			helpers.LoginCF()
   105  		})
   106  
   107  		Context("when the isolation segment does not exist", func() {
   108  			It("creates the isolation segment", func() {
   109  				session := helpers.CF("create-isolation-segment", isolationSegmentName)
   110  				userName, _ := helpers.GetCredentials()
   111  				Eventually(session).Should(Say("Creating isolation segment %s as %s...", isolationSegmentName, userName))
   112  				Eventually(session).Should(Say("OK"))
   113  				Eventually(session).Should(Exit(0))
   114  			})
   115  		})
   116  
   117  		Context("when the isolation segment already exists", func() {
   118  			BeforeEach(func() {
   119  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
   120  			})
   121  
   122  			It("returns an ok", func() {
   123  				session := helpers.CF("create-isolation-segment", isolationSegmentName)
   124  				Eventually(session.Err).Should(Say("Isolation segment %s already exists", isolationSegmentName))
   125  				Eventually(session).Should(Say("OK"))
   126  				Eventually(session).Should(Exit(0))
   127  			})
   128  		})
   129  	})
   130  })