github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/integration/isolated/v3_start_application_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"os"
     5  	"regexp"
     6  
     7  	"code.cloudfoundry.org/cli/integration/helpers"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("v3-start-application command", func() {
    15  	var (
    16  		orgName   string
    17  		spaceName string
    18  		appName   string
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		Skip("don't run in the pipeline until cf-deployment master supports it")
    23  
    24  		orgName = helpers.NewOrgName()
    25  		spaceName = helpers.NewSpaceName()
    26  		appName = helpers.PrefixedRandomName("app")
    27  	})
    28  
    29  	Describe("help", func() {
    30  		Context("when --help flag is set", func() {
    31  			It("Displays command usage to output", func() {
    32  				session := helpers.CF("v3-start", "--help")
    33  
    34  				Eventually(session.Out).Should(Say("NAME:"))
    35  				Eventually(session.Out).Should(Say("v3-start - Start an app"))
    36  				Eventually(session.Out).Should(Say("USAGE:"))
    37  				Eventually(session.Out).Should(Say("cf v3-start APP_NAME"))
    38  
    39  				Eventually(session).Should(Exit(0))
    40  			})
    41  		})
    42  	})
    43  
    44  	Context("when the app name is not provided", func() {
    45  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    46  			session := helpers.CF("v3-start")
    47  
    48  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    49  			Eventually(session.Out).Should(Say("NAME:"))
    50  			Eventually(session).Should(Exit(1))
    51  		})
    52  	})
    53  
    54  	Context("when the environment is not setup correctly", func() {
    55  		Context("when no API endpoint is set", func() {
    56  			BeforeEach(func() {
    57  				helpers.UnsetAPI()
    58  			})
    59  
    60  			It("fails with no API endpoint set message", func() {
    61  				session := helpers.CF("v3-start", appName)
    62  				Eventually(session).Should(Say("FAILED"))
    63  				Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\."))
    64  				Eventually(session).Should(Exit(1))
    65  			})
    66  		})
    67  
    68  		Context("when not logged in", func() {
    69  			BeforeEach(func() {
    70  				helpers.LogoutCF()
    71  			})
    72  
    73  			It("fails with not logged in message", func() {
    74  				session := helpers.CF("v3-start", appName)
    75  				Eventually(session).Should(Say("FAILED"))
    76  				Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\."))
    77  				Eventually(session).Should(Exit(1))
    78  			})
    79  		})
    80  
    81  		Context("when there is no org set", func() {
    82  			BeforeEach(func() {
    83  				helpers.LogoutCF()
    84  				helpers.LoginCF()
    85  			})
    86  
    87  			It("fails with no org targeted error message", func() {
    88  				session := helpers.CF("v3-start", appName)
    89  				Eventually(session.Out).Should(Say("FAILED"))
    90  				Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\."))
    91  				Eventually(session).Should(Exit(1))
    92  			})
    93  		})
    94  
    95  		Context("when there is no space set", func() {
    96  			BeforeEach(func() {
    97  				helpers.LogoutCF()
    98  				helpers.LoginCF()
    99  				helpers.TargetOrg(ReadOnlyOrg)
   100  			})
   101  
   102  			It("fails with no space targeted error message", func() {
   103  				session := helpers.CF("v3-start", appName)
   104  				Eventually(session.Out).Should(Say("FAILED"))
   105  				Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\."))
   106  				Eventually(session).Should(Exit(1))
   107  			})
   108  		})
   109  	})
   110  
   111  	Context("when the environment is set up correctly", func() {
   112  		BeforeEach(func() {
   113  			setupCF(orgName, spaceName)
   114  		})
   115  
   116  		Context("when the app exists", func() {
   117  			BeforeEach(func() {
   118  				var packageGUID string
   119  				Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0))
   120  
   121  				helpers.WithHelloWorldApp(func(appDir string) {
   122  					prevDir, err := os.Getwd()
   123  					Expect(err).ToNot(HaveOccurred())
   124  
   125  					err = os.Chdir(appDir)
   126  					Expect(err).ToNot(HaveOccurred())
   127  					defer func() {
   128  						err = os.Chdir(prevDir)
   129  						Expect(err).ToNot(HaveOccurred())
   130  					}()
   131  
   132  					pkgSession := helpers.CF("v3-create-package", appName)
   133  					Eventually(pkgSession).Should(Exit(0))
   134  					regex, err := regexp.Compile(`package guid: (.+)`)
   135  					Expect(err).ToNot(HaveOccurred())
   136  					matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents()))
   137  					Expect(matches).To(HaveLen(2))
   138  
   139  					packageGUID = matches[1]
   140  				})
   141  
   142  				stageSession := helpers.CF("v3-stage", appName, "--package-guid", packageGUID)
   143  				Eventually(stageSession).Should(Exit(0))
   144  
   145  				regex, err := regexp.Compile(`droplet: (.+)`)
   146  				Expect(err).ToNot(HaveOccurred())
   147  				matches := regex.FindStringSubmatch(string(stageSession.Out.Contents()))
   148  				Expect(matches).To(HaveLen(2))
   149  
   150  				dropletGUID := matches[1]
   151  				setDropletSession := helpers.CF("v3-set-droplet", appName, "--droplet-guid", dropletGUID)
   152  				Eventually(setDropletSession).Should(Exit(0))
   153  			})
   154  
   155  			It("starts the app", func() {
   156  				userName, _ := helpers.GetCredentials()
   157  
   158  				session := helpers.CF("v3-start", appName)
   159  				Eventually(session.Out).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   160  				Eventually(session.Out).Should(Say("OK"))
   161  
   162  				Eventually(session).Should(Exit(0))
   163  			})
   164  
   165  			Context("when the app does not exist", func() {
   166  				It("displays app not found and exits 1", func() {
   167  					invalidAppName := "invalid-app-name"
   168  					session := helpers.CF("v3-start", invalidAppName)
   169  					userName, _ := helpers.GetCredentials()
   170  
   171  					Eventually(session.Out).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", invalidAppName, orgName, spaceName, userName))
   172  					Eventually(session.Err).Should(Say("App %s not found", invalidAppName))
   173  					Eventually(session.Out).Should(Say("FAILED"))
   174  
   175  					Eventually(session).Should(Exit(1))
   176  				})
   177  			})
   178  		})
   179  	})
   180  })