github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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  		It("fails with the appropriate errors", func() {
    38  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "create-isolation-segment", "isolation-seg-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("create-isolation-segment", 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("create-isolation-segment", 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  		BeforeEach(func() {
    82  			helpers.LoginCF()
    83  		})
    84  
    85  		Context("when the isolation segment does not exist", func() {
    86  			It("creates the isolation segment", func() {
    87  				session := helpers.CF("create-isolation-segment", isolationSegmentName)
    88  				userName, _ := helpers.GetCredentials()
    89  				Eventually(session).Should(Say("Creating isolation segment %s as %s...", isolationSegmentName, userName))
    90  				Eventually(session).Should(Say("OK"))
    91  				Eventually(session).Should(Exit(0))
    92  			})
    93  		})
    94  
    95  		Context("when the isolation segment already exists", func() {
    96  			BeforeEach(func() {
    97  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
    98  			})
    99  
   100  			It("returns an ok", func() {
   101  				session := helpers.CF("create-isolation-segment", isolationSegmentName)
   102  				Eventually(session.Err).Should(Say("Isolation segment %s already exists", isolationSegmentName))
   103  				Eventually(session).Should(Say("OK"))
   104  				Eventually(session).Should(Exit(0))
   105  			})
   106  		})
   107  	})
   108  })