github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/isolated/create_isolation_segment_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  	. "github.com/onsi/gomega/ghttp"
    11  )
    12  
    13  var _ = Describe("create-isolation-segment command", func() {
    14  	var isolationSegmentName string
    15  
    16  	BeforeEach(func() {
    17  		helpers.SkipIfVersionLessThan(ccversion.MinVersionIsolationSegmentV3)
    18  
    19  		isolationSegmentName = helpers.NewIsolationSegmentName()
    20  	})
    21  
    22  	Describe("help", func() {
    23  		When("--help flag is set", func() {
    24  			It("Displays command usage to output", func() {
    25  				session := helpers.CF("create-isolation-segment", "--help")
    26  				Eventually(session).Should(Say("NAME:"))
    27  				Eventually(session).Should(Say("create-isolation-segment - Create an isolation segment"))
    28  				Eventually(session).Should(Say("USAGE:"))
    29  				Eventually(session).Should(Say("cf create-isolation-segment SEGMENT_NAME"))
    30  				Eventually(session).Should(Say("NOTES:"))
    31  				Eventually(session).Should(Say("The isolation segment name must match the placement tag applied to the Diego cell."))
    32  				Eventually(session).Should(Say("SEE ALSO:"))
    33  				Eventually(session).Should(Say("enable-org-isolation, isolation-segments"))
    34  				Eventually(session).Should(Exit(0))
    35  			})
    36  		})
    37  	})
    38  
    39  	When("the environment is not setup correctly", func() {
    40  		It("fails with the appropriate errors", func() {
    41  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "create-isolation-segment", "isolation-seg-name")
    42  		})
    43  
    44  		When("the v3 api version is lower than the minimum version", func() {
    45  			var server *Server
    46  
    47  			BeforeEach(func() {
    48  				server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion)
    49  			})
    50  
    51  			AfterEach(func() {
    52  				server.Close()
    53  			})
    54  
    55  			It("fails with error message that the minimum version is not met", func() {
    56  				session := helpers.CF("create-isolation-segment", isolationSegmentName)
    57  				Eventually(session).Should(Say("FAILED"))
    58  				Eventually(session.Err).Should(Say(`This command requires CF API version 3\.11\.0 or higher\.`))
    59  				Eventually(session).Should(Exit(1))
    60  			})
    61  		})
    62  	})
    63  
    64  	When("the environment is set up correctly", func() {
    65  		BeforeEach(func() {
    66  			helpers.LoginCF()
    67  		})
    68  
    69  		When("the isolation segment does not exist", func() {
    70  			It("creates the isolation segment", func() {
    71  				session := helpers.CF("create-isolation-segment", isolationSegmentName)
    72  				userName, _ := helpers.GetCredentials()
    73  				Eventually(session).Should(Say("Creating isolation segment %s as %s...", isolationSegmentName, userName))
    74  				Eventually(session).Should(Say("OK"))
    75  				Eventually(session).Should(Exit(0))
    76  			})
    77  		})
    78  
    79  		When("the isolation segment already exists", func() {
    80  			BeforeEach(func() {
    81  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
    82  			})
    83  
    84  			It("returns an ok", func() {
    85  				session := helpers.CF("create-isolation-segment", isolationSegmentName)
    86  				Eventually(session.Err).Should(Say("Isolation segment %s already exists", isolationSegmentName))
    87  				Eventually(session).Should(Say("OK"))
    88  				Eventually(session).Should(Exit(0))
    89  			})
    90  		})
    91  	})
    92  })