github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/isolated/delete_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("delete-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("delete-isolation-segment", "--help")
    26  				Eventually(session).Should(Say("NAME:"))
    27  				Eventually(session).Should(Say("delete-isolation-segment - Delete an isolation segment"))
    28  				Eventually(session).Should(Say("USAGE:"))
    29  				Eventually(session).Should(Say("cf delete-isolation-segment SEGMENT_NAME"))
    30  				Eventually(session).Should(Say("SEE ALSO:"))
    31  				Eventually(session).Should(Say("disable-org-isolation, isolation-segments"))
    32  				Eventually(session).Should(Exit(0))
    33  			})
    34  		})
    35  	})
    36  
    37  	When("the environment is not setup correctly", func() {
    38  		It("fails with the appropriate errors", func() {
    39  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "delete-isolation-segment", "isolation-segment-name")
    40  		})
    41  
    42  		When("the v3 api version is lower than the minimum version", func() {
    43  			var server *Server
    44  
    45  			BeforeEach(func() {
    46  				server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion)
    47  			})
    48  
    49  			AfterEach(func() {
    50  				server.Close()
    51  			})
    52  
    53  			It("fails with error message that the minimum version is not met", func() {
    54  				session := helpers.CF("delete-isolation-segment", isolationSegmentName)
    55  				Eventually(session).Should(Say("FAILED"))
    56  				Eventually(session.Err).Should(Say(`This command requires CF API version 3\.11\.0 or higher\.`))
    57  				Eventually(session).Should(Exit(1))
    58  			})
    59  		})
    60  	})
    61  
    62  	When("the environment is set up correctly", func() {
    63  		BeforeEach(func() {
    64  			helpers.LoginCF()
    65  		})
    66  
    67  		When("the isolation segment exists", func() {
    68  			BeforeEach(func() {
    69  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
    70  			})
    71  
    72  			When("passed the force flag", func() {
    73  				It("deletes the isolation segment", func() {
    74  					session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName)
    75  					userName, _ := helpers.GetCredentials()
    76  					Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName))
    77  					Eventually(session).Should(Say("OK"))
    78  					Eventually(session).Should(Exit(0))
    79  				})
    80  			})
    81  
    82  			When("the force flag is not provided", func() {
    83  				var buffer *Buffer
    84  
    85  				BeforeEach(func() {
    86  					buffer = NewBuffer()
    87  				})
    88  
    89  				When("'yes' is inputted", func() {
    90  					BeforeEach(func() {
    91  						buffer.Write([]byte("y\n"))
    92  					})
    93  
    94  					It("deletes the isolation segment", func() {
    95  						session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName)
    96  						Eventually(session).Should(Say(`Really delete the isolation segment %s\?`, isolationSegmentName))
    97  
    98  						userName, _ := helpers.GetCredentials()
    99  						Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName))
   100  						Eventually(session).Should(Say("OK"))
   101  						Eventually(session).Should(Exit(0))
   102  					})
   103  				})
   104  
   105  				When("'no' is inputted", func() {
   106  					BeforeEach(func() {
   107  						buffer.Write([]byte("n\n"))
   108  					})
   109  
   110  					It("cancels the deletion", func() {
   111  						session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName)
   112  						Eventually(session).Should(Say(`Really delete the isolation segment %s\?`, isolationSegmentName))
   113  						Eventually(session).Should(Say("Delete cancelled"))
   114  						Eventually(session).Should(Exit(0))
   115  					})
   116  				})
   117  
   118  				When("using the default value", func() {
   119  					BeforeEach(func() {
   120  						buffer.Write([]byte("\n"))
   121  					})
   122  
   123  					It("cancels the deletion", func() {
   124  						session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName)
   125  						Eventually(session).Should(Say(`Really delete the isolation segment %s\?`, isolationSegmentName))
   126  						Eventually(session).Should(Say("Delete cancelled"))
   127  						Eventually(session).Should(Exit(0))
   128  					})
   129  				})
   130  			})
   131  		})
   132  
   133  		When("the isolation segment does not exist", func() {
   134  			It("returns an ok and warning", func() {
   135  				session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName)
   136  				Eventually(session.Err).Should(Say("Isolation segment %s does not exist.", isolationSegmentName))
   137  				Eventually(session).Should(Say("OK"))
   138  				Eventually(session).Should(Exit(0))
   139  			})
   140  		})
   141  	})
   142  })