github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/integration/shared/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, err := regexp.Compile(`package guid: (.+)`)
    96  					Expect(err).ToNot(HaveOccurred())
    97  					matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents()))
    98  					Expect(matches).To(HaveLen(2))
    99  
   100  					packageGUID = matches[1]
   101  				})
   102  
   103  				stageSession := helpers.CF("v3-stage", appName, "--package-guid", packageGUID)
   104  				Eventually(stageSession).Should(Exit(0))
   105  
   106  				regex, err := regexp.Compile(`droplet guid:\s+(.+)`)
   107  				Expect(err).ToNot(HaveOccurred())
   108  				matches := regex.FindStringSubmatch(string(stageSession.Out.Contents()))
   109  				Expect(matches).To(HaveLen(2))
   110  
   111  				dropletGUID = matches[1]
   112  			})
   113  
   114  			It("sets the droplet for the app", func() {
   115  				userName, _ := helpers.GetCredentials()
   116  
   117  				session := helpers.CF("v3-set-droplet", appName, "-d", dropletGUID)
   118  				Eventually(session).Should(Say(`Setting app %s to droplet %s in org %s / space %s as %s\.\.\.`, appName, dropletGUID, orgName, spaceName, userName))
   119  				Eventually(session).Should(Say("OK"))
   120  
   121  				Eventually(session).Should(Exit(0))
   122  			})
   123  
   124  			When("the app does not exist", func() {
   125  				It("displays app not found and exits 1", func() {
   126  					invalidAppName := "invalid-app-name"
   127  					session := helpers.CF("v3-set-droplet", invalidAppName, "-d", dropletGUID)
   128  					userName, _ := helpers.GetCredentials()
   129  
   130  					Eventually(session).Should(Say(`Setting app %s to droplet %s in org %s / space %s as %s\.\.\.`, invalidAppName, dropletGUID, orgName, spaceName, userName))
   131  					Eventually(session.Err).Should(Say("App %s not found", invalidAppName))
   132  					Eventually(session).Should(Say("FAILED"))
   133  
   134  					Eventually(session).Should(Exit(1))
   135  				})
   136  			})
   137  
   138  			When("the droplet does not exist", func() {
   139  				It("displays droplet not found and exits 1", func() {
   140  					invalidDropletGUID := "some-droplet-guid"
   141  					session := helpers.CF("v3-set-droplet", appName, "-d", invalidDropletGUID)
   142  					userName, _ := helpers.GetCredentials()
   143  
   144  					Eventually(session).Should(Say(`Setting app %s to droplet %s in org %s / space %s as %s\.\.\.`, appName, invalidDropletGUID, orgName, spaceName, userName))
   145  					Eventually(session.Err).Should(Say(`Unable to assign droplet: Unable to assign current droplet\. Ensure the droplet exists and belongs to this app\.`))
   146  					Eventually(session).Should(Say("FAILED"))
   147  					Eventually(session).Should(Exit(1))
   148  				})
   149  			})
   150  		})
   151  	})
   152  })