github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/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  )
    10  
    11  var _ = Describe("create-isolation-segment command", func() {
    12  	var isolationSegmentName string
    13  
    14  	BeforeEach(func() {
    15  		isolationSegmentName = helpers.NewIsolationSegmentName()
    16  	})
    17  
    18  	Describe("help", func() {
    19  		When("--help flag is set", func() {
    20  			It("Displays command usage to output", func() {
    21  				session := helpers.CF("create-isolation-segment", "--help")
    22  				Eventually(session).Should(Say("NAME:"))
    23  				Eventually(session).Should(Say("create-isolation-segment - Create an isolation segment"))
    24  				Eventually(session).Should(Say("USAGE:"))
    25  				Eventually(session).Should(Say("cf create-isolation-segment SEGMENT_NAME"))
    26  				Eventually(session).Should(Say("NOTES:"))
    27  				Eventually(session).Should(Say("The isolation segment name must match the placement tag applied to the Diego cell."))
    28  				Eventually(session).Should(Say("SEE ALSO:"))
    29  				Eventually(session).Should(Say("enable-org-isolation, isolation-segments"))
    30  				Eventually(session).Should(Exit(0))
    31  			})
    32  		})
    33  	})
    34  
    35  	When("the environment is not setup correctly", func() {
    36  		It("fails with the appropriate errors", func() {
    37  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "create-isolation-segment", "isolation-seg-name")
    38  		})
    39  	})
    40  
    41  	When("the environment is set up correctly", func() {
    42  		BeforeEach(func() {
    43  			helpers.LoginCF()
    44  		})
    45  
    46  		When("the isolation segment does not exist", func() {
    47  			It("creates the isolation segment", func() {
    48  				session := helpers.CF("create-isolation-segment", isolationSegmentName)
    49  				userName, _ := helpers.GetCredentials()
    50  				Eventually(session).Should(Say("Creating isolation segment %s as %s...", isolationSegmentName, userName))
    51  				Eventually(session).Should(Say("OK"))
    52  				Eventually(session).Should(Exit(0))
    53  			})
    54  		})
    55  
    56  		When("the isolation segment already exists", func() {
    57  			BeforeEach(func() {
    58  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
    59  			})
    60  
    61  			It("returns an ok", func() {
    62  				session := helpers.CF("create-isolation-segment", isolationSegmentName)
    63  				Eventually(session.Err).Should(Say("Isolation segment '%s' already exists", isolationSegmentName))
    64  				Eventually(session).Should(Say("OK"))
    65  				Eventually(session).Should(Exit(0))
    66  			})
    67  		})
    68  	})
    69  })