github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/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  		Context("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  	Context("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  		Context("when the v3 api does not exist", func() {
    43  			var server *Server
    44  
    45  			BeforeEach(func() {
    46  				server = helpers.StartAndTargetServerWithoutV3API()
    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  		Context("when the v3 api version is lower than the minimum version", func() {
    62  			var server *Server
    63  
    64  			BeforeEach(func() {
    65  				server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, "3.0.0")
    66  			})
    67  
    68  			AfterEach(func() {
    69  				server.Close()
    70  			})
    71  
    72  			It("fails with error message that the minimum version is not met", func() {
    73  				session := helpers.CF("delete-isolation-segment", isolationSegmentName)
    74  				Eventually(session).Should(Say("FAILED"))
    75  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\."))
    76  				Eventually(session).Should(Exit(1))
    77  			})
    78  		})
    79  	})
    80  
    81  	Context("when the environment is set up correctly", func() {
    82  		BeforeEach(func() {
    83  			helpers.LoginCF()
    84  		})
    85  
    86  		Context("when the isolation segment exists", func() {
    87  			BeforeEach(func() {
    88  				Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0))
    89  			})
    90  
    91  			Context("when passed the force flag", func() {
    92  				It("deletes the isolation segment", func() {
    93  					session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName)
    94  					userName, _ := helpers.GetCredentials()
    95  					Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName))
    96  					Eventually(session).Should(Say("OK"))
    97  					Eventually(session).Should(Exit(0))
    98  				})
    99  			})
   100  
   101  			Context("when the force flag is not provided", func() {
   102  				var buffer *Buffer
   103  
   104  				BeforeEach(func() {
   105  					buffer = NewBuffer()
   106  				})
   107  
   108  				Context("when 'yes' is inputted", func() {
   109  					BeforeEach(func() {
   110  						buffer.Write([]byte("y\n"))
   111  					})
   112  
   113  					It("deletes the isolation segment", func() {
   114  						session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName)
   115  						Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName))
   116  
   117  						userName, _ := helpers.GetCredentials()
   118  						Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName))
   119  						Eventually(session).Should(Say("OK"))
   120  						Eventually(session).Should(Exit(0))
   121  					})
   122  				})
   123  
   124  				Context("when 'no' is inputted", func() {
   125  					BeforeEach(func() {
   126  						buffer.Write([]byte("n\n"))
   127  					})
   128  
   129  					It("cancels the deletion", func() {
   130  						session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName)
   131  						Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName))
   132  						Eventually(session).Should(Say("Delete cancelled"))
   133  						Eventually(session).Should(Exit(0))
   134  					})
   135  				})
   136  
   137  				Context("when using the default value", func() {
   138  					BeforeEach(func() {
   139  						buffer.Write([]byte("\n"))
   140  					})
   141  
   142  					It("cancels the deletion", func() {
   143  						session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName)
   144  						Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName))
   145  						Eventually(session).Should(Say("Delete cancelled"))
   146  						Eventually(session).Should(Exit(0))
   147  					})
   148  				})
   149  			})
   150  		})
   151  
   152  		Context("when the isolation segment does not exist", func() {
   153  			It("returns an ok and warning", func() {
   154  				session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName)
   155  				Eventually(session.Err).Should(Say("Isolation segment %s does not exist.", isolationSegmentName))
   156  				Eventually(session).Should(Say("OK"))
   157  				Eventually(session).Should(Exit(0))
   158  			})
   159  		})
   160  	})
   161  })