github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/isolated/delete_security_group_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("delete-security-group command", func() {
    12  	When("the security-group name is not provided", func() {
    13  		It("displays an error and help", func() {
    14  			session := helpers.CF("delete-security-group")
    15  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SECURITY_GROUP` was not provided"))
    16  			Eventually(session).Should(Say("USAGE"))
    17  			Eventually(session).Should(Exit(1))
    18  		})
    19  	})
    20  
    21  	When("the security-group does not exist", func() {
    22  		BeforeEach(func() {
    23  			helpers.LoginCF()
    24  		})
    25  
    26  		It("displays a warning and exits 0", func() {
    27  			username, _ := helpers.GetCredentials()
    28  			session := helpers.CF("delete-security-group", "-f", "please-do-not-exist-in-real-life")
    29  			Eventually(session).Should(Say("Deleting security group please-do-not-exist-in-real-life as %s", username))
    30  			Eventually(session).Should(Say("OK"))
    31  			Eventually(session).Should(Say("Security group please-do-not-exist-in-real-life does not exist"))
    32  			Eventually(session).Should(Exit(0))
    33  		})
    34  	})
    35  
    36  	When("the security group exists", func() {
    37  		var (
    38  			securityGroupName string
    39  			ports             string
    40  			description       string
    41  		)
    42  
    43  		BeforeEach(func() {
    44  			helpers.LoginCF()
    45  		})
    46  
    47  		When("the -f flag not is provided", func() {
    48  			var buffer *Buffer
    49  
    50  			BeforeEach(func() {
    51  				buffer = NewBuffer()
    52  			})
    53  
    54  			When("the user enters 'y'", func() {
    55  				BeforeEach(func() {
    56  					securityGroupName = helpers.NewSecurityGroupName()
    57  					ports = "8080"
    58  					description = "my favorite description"
    59  					securityGroup := helpers.NewSecurityGroup(securityGroupName, "tcp", "0.0.0.0", &ports, &description)
    60  					helpers.CreateSecurityGroup(securityGroup)
    61  
    62  					_, err := buffer.Write([]byte("y\n"))
    63  					Expect(err).ToNot(HaveOccurred())
    64  				})
    65  
    66  				It("deletes the security group", func() {
    67  					username, _ := helpers.GetCredentials()
    68  					session := helpers.CFWithStdin(buffer, "delete-security-group", securityGroupName)
    69  					Eventually(session).Should(Say("Deleting security group %s as %s", securityGroupName, username))
    70  					Eventually(session).Should(Say(`Really delete the security group %s`, securityGroupName))
    71  					Eventually(session).Should(Say("OK"))
    72  					Eventually(session).Should(Exit(0))
    73  					Eventually(helpers.CF("security-group", securityGroupName)).Should(Exit(1))
    74  				})
    75  			})
    76  
    77  			When("the user enters 'n'", func() {
    78  				BeforeEach(func() {
    79  					_, err := buffer.Write([]byte("n\n"))
    80  					Expect(err).ToNot(HaveOccurred())
    81  				})
    82  
    83  				It("does not delete the security group", func() {
    84  					session := helpers.CFWithStdin(buffer, "delete-security-group", securityGroupName)
    85  					Eventually(session).Should(Say(`Really delete the security group %s`, securityGroupName))
    86  					Eventually(session).Should(Say("Delete cancelled"))
    87  					Eventually(session).Should(Exit(0))
    88  				})
    89  			})
    90  
    91  			When("the user enters the default input (hits return)", func() {
    92  				BeforeEach(func() {
    93  					_, err := buffer.Write([]byte("\n"))
    94  					Expect(err).ToNot(HaveOccurred())
    95  				})
    96  
    97  				It("does not delete the security group", func() {
    98  					session := helpers.CFWithStdin(buffer, "delete-security-group", securityGroupName)
    99  					Eventually(session).Should(Say(`Really delete the security group %s`, securityGroupName))
   100  					Eventually(session).Should(Say("Delete cancelled"))
   101  					Eventually(session).Should(Exit(0))
   102  				})
   103  			})
   104  
   105  			When("the user enters an invalid answer", func() {
   106  				BeforeEach(func() {
   107  					// The second '\n' is intentional. Otherwise the buffer will be
   108  					// closed while the interaction is still waiting for input; it gets
   109  					// an EOF and causes an error.
   110  					_, err := buffer.Write([]byte("wat\n\n"))
   111  					Expect(err).ToNot(HaveOccurred())
   112  				})
   113  
   114  				It("asks again", func() {
   115  					session := helpers.CFWithStdin(buffer, "delete-security-group", securityGroupName)
   116  					Eventually(session).Should(Say(`Really delete the security group %s`, securityGroupName))
   117  					Eventually(session).Should(Say("Delete cancelled"))
   118  					Eventually(session).Should(Exit(0))
   119  				})
   120  			})
   121  		})
   122  
   123  		When("the -f flag is provided", func() {
   124  			BeforeEach(func() {
   125  				securityGroupName = helpers.NewSecurityGroupName()
   126  				ports = "8080"
   127  				description = "my favorite description"
   128  				securityGroup := helpers.NewSecurityGroup(securityGroupName, "tcp", "0.0.0.0", &ports, &description)
   129  				helpers.CreateSecurityGroup(securityGroup)
   130  			})
   131  
   132  			It("deletes the security group", func() {
   133  				username, _ := helpers.GetCredentials()
   134  				session := helpers.CF("delete-security-group", securityGroupName, "-f")
   135  				Eventually(session).Should(Say("Deleting security group %s as %s", securityGroupName, username))
   136  				Eventually(session).Should(Say("OK"))
   137  				Eventually(session).Should(Exit(0))
   138  				Eventually(helpers.CF("security-group", securityGroupName)).Should(Exit(1))
   139  			})
   140  		})
   141  	})
   142  })