github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v6/experimental/v3_set_droplet_command_test.go (about)

     1  package experimental
     2  
     3  import (
     4  	"regexp"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gbytes"
    10  	. "github.com/onsi/gomega/gexec"
    11  )
    12  
    13  var _ = Describe("v3-set-droplet command", func() {
    14  	var (
    15  		orgName   string
    16  		spaceName string
    17  		appName   string
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		orgName = helpers.NewOrgName()
    22  		spaceName = helpers.NewSpaceName()
    23  		appName = helpers.PrefixedRandomName("app")
    24  	})
    25  
    26  	Describe("help", func() {
    27  		When("--help flag is set", func() {
    28  			It("Displays command usage to output", func() {
    29  				session := helpers.CF("v3-set-droplet", "--help")
    30  
    31  				Eventually(session).Should(Say("NAME:"))
    32  				Eventually(session).Should(Say("v3-set-droplet - Set the droplet used to run an app"))
    33  				Eventually(session).Should(Say("USAGE:"))
    34  				Eventually(session).Should(Say("cf v3-set-droplet APP_NAME -d DROPLET_GUID"))
    35  				Eventually(session).Should(Say("OPTIONS:"))
    36  				Eventually(session).Should(Say(`--droplet-guid, -d\s+The guid of the droplet to use`))
    37  
    38  				Eventually(session).Should(Exit(0))
    39  			})
    40  		})
    41  	})
    42  
    43  	When("the app name is not provided", func() {
    44  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    45  			session := helpers.CF("v3-set-droplet", "-d", "some-droplet-guid")
    46  
    47  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    48  			Eventually(session).Should(Say("NAME:"))
    49  			Eventually(session).Should(Exit(1))
    50  		})
    51  	})
    52  
    53  	It("displays the experimental warning", func() {
    54  		session := helpers.CF("v3-set-droplet", appName, "--droplet-guid", "some-droplet-guid")
    55  		Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    56  		Eventually(session).Should(Exit())
    57  	})
    58  
    59  	When("the package GUID flag is missing", func() {
    60  		It("displays incorrect usage", func() {
    61  			session := helpers.CF("v3-set-droplet", "some-app")
    62  
    63  			Eventually(session.Err).Should(Say("Incorrect Usage: the required flag `-d, --droplet-guid' was not specified"))
    64  			Eventually(session).Should(Say("NAME:"))
    65  
    66  			Eventually(session).Should(Exit(1))
    67  		})
    68  	})
    69  
    70  	When("the environment is not setup correctly", func() {
    71  		It("fails with the appropriate errors", func() {
    72  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-set-droplet", appName, "--droplet-guid", "some-droplet-guid")
    73  		})
    74  	})
    75  
    76  	When("the environment is set up correctly", func() {
    77  		BeforeEach(func() {
    78  			helpers.SetupCF(orgName, spaceName)
    79  		})
    80  
    81  		AfterEach(func() {
    82  			helpers.QuickDeleteOrg(orgName)
    83  		})
    84  
    85  		When("the app exists", func() {
    86  			var dropletGUID string
    87  
    88  			BeforeEach(func() {
    89  				var packageGUID string
    90  				Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0))
    91  
    92  				helpers.WithHelloWorldApp(func(appDir string) {
    93  					pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-create-package", appName)
    94  					Eventually(pkgSession).Should(Exit(0))
    95  					regex := regexp.MustCompile(`package guid: (.+)`)
    96  					matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents()))
    97  					Expect(matches).To(HaveLen(2))
    98  
    99  					packageGUID = matches[1]
   100  				})
   101  
   102  				stageSession := helpers.CF("v3-stage", appName, "--package-guid", packageGUID)
   103  				Eventually(stageSession).Should(Exit(0))
   104  
   105  				regex := regexp.MustCompile(`droplet guid:\s+(.+)`)
   106  				matches := regex.FindStringSubmatch(string(stageSession.Out.Contents()))
   107  				Expect(matches).To(HaveLen(2))
   108  
   109  				dropletGUID = matches[1]
   110  			})
   111  
   112  			It("sets the droplet for the app", func() {
   113  				userName, _ := helpers.GetCredentials()
   114  
   115  				session := helpers.CF("v3-set-droplet", appName, "-d", dropletGUID)
   116  				Eventually(session).Should(Say(`Setting app %s to droplet %s in org %s / space %s as %s\.\.\.`, appName, dropletGUID, orgName, spaceName, userName))
   117  				Eventually(session).Should(Say("OK"))
   118  
   119  				Eventually(session).Should(Exit(0))
   120  			})
   121  
   122  			When("the app does not exist", func() {
   123  				It("displays app not found and exits 1", func() {
   124  					invalidAppName := "invalid-app-name"
   125  					session := helpers.CF("v3-set-droplet", invalidAppName, "-d", dropletGUID)
   126  					userName, _ := helpers.GetCredentials()
   127  
   128  					Eventually(session).Should(Say(`Setting app %s to droplet %s in org %s / space %s as %s\.\.\.`, invalidAppName, dropletGUID, orgName, spaceName, userName))
   129  					Eventually(session.Err).Should(Say("App '%s' not found", invalidAppName))
   130  					Eventually(session).Should(Say("FAILED"))
   131  
   132  					Eventually(session).Should(Exit(1))
   133  				})
   134  			})
   135  
   136  			When("the droplet does not exist", func() {
   137  				It("displays droplet not found and exits 1", func() {
   138  					invalidDropletGUID := "some-droplet-guid"
   139  					session := helpers.CF("v3-set-droplet", appName, "-d", invalidDropletGUID)
   140  					userName, _ := helpers.GetCredentials()
   141  
   142  					Eventually(session).Should(Say(`Setting app %s to droplet %s in org %s / space %s as %s\.\.\.`, appName, invalidDropletGUID, orgName, spaceName, userName))
   143  					Eventually(session.Err).Should(Say(`Unable to assign droplet: Unable to assign current droplet\. Ensure the droplet exists and belongs to this app\.`))
   144  					Eventually(session).Should(Say("FAILED"))
   145  					Eventually(session).Should(Exit(1))
   146  				})
   147  			})
   148  		})
   149  	})
   150  })