github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v6/experimental/v3_start_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-start-application 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-start", "--help")
    30  
    31  				Eventually(session).Should(Say("NAME:"))
    32  				Eventually(session).Should(Say("v3-start - Start an app"))
    33  				Eventually(session).Should(Say("USAGE:"))
    34  				Eventually(session).Should(Say("cf v3-start APP_NAME"))
    35  
    36  				Eventually(session).Should(Exit(0))
    37  			})
    38  		})
    39  	})
    40  
    41  	When("the app name is not provided", func() {
    42  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    43  			session := helpers.CF("v3-start")
    44  
    45  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    46  			Eventually(session).Should(Say("NAME:"))
    47  			Eventually(session).Should(Exit(1))
    48  		})
    49  	})
    50  
    51  	It("displays the experimental warning", func() {
    52  		session := helpers.CF("v3-start", appName)
    53  		Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    54  		Eventually(session).Should(Exit())
    55  	})
    56  
    57  	When("the environment is not setup correctly", func() {
    58  		It("fails with the appropriate errors", func() {
    59  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-start", appName)
    60  		})
    61  	})
    62  
    63  	When("the environment is set up correctly", func() {
    64  		BeforeEach(func() {
    65  			helpers.SetupCF(orgName, spaceName)
    66  		})
    67  
    68  		AfterEach(func() {
    69  			helpers.QuickDeleteOrg(orgName)
    70  		})
    71  
    72  		When("the app exists", func() {
    73  			BeforeEach(func() {
    74  				var packageGUID string
    75  				Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0))
    76  
    77  				helpers.WithHelloWorldApp(func(dir string) {
    78  					pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "v3-create-package", appName)
    79  					Eventually(pkgSession).Should(Exit(0))
    80  					regex := regexp.MustCompile(`package guid: (.+)`)
    81  					matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents()))
    82  					Expect(matches).To(HaveLen(2))
    83  
    84  					packageGUID = matches[1]
    85  				})
    86  
    87  				stageSession := helpers.CF("v3-stage", appName, "--package-guid", packageGUID)
    88  				Eventually(stageSession).Should(Exit(0))
    89  
    90  				regex := regexp.MustCompile(`droplet guid:\s+(.+)`)
    91  				matches := regex.FindStringSubmatch(string(stageSession.Out.Contents()))
    92  				Expect(matches).To(HaveLen(2))
    93  
    94  				dropletGUID := matches[1]
    95  				setDropletSession := helpers.CF("v3-set-droplet", appName, "--droplet-guid", dropletGUID)
    96  				Eventually(setDropletSession).Should(Exit(0))
    97  			})
    98  
    99  			It("starts the app", func() {
   100  				userName, _ := helpers.GetCredentials()
   101  
   102  				session := helpers.CF("v3-start", appName)
   103  				Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   104  				Eventually(session).Should(Say("OK"))
   105  
   106  				Eventually(session).Should(Exit(0))
   107  			})
   108  
   109  			When("the app is already started", func() {
   110  				BeforeEach(func() {
   111  					Eventually(helpers.CF("v3-start", appName)).Should(Exit(0))
   112  				})
   113  
   114  				It("displays app already started and exits 0", func() {
   115  					session := helpers.CF("v3-start", appName)
   116  
   117  					Eventually(session.Err).Should(Say("App %s is already started", appName))
   118  					Eventually(session).Should(Say("OK"))
   119  
   120  					Eventually(session).Should(Exit(0))
   121  				})
   122  			})
   123  		})
   124  
   125  		When("the app does not exist", func() {
   126  			It("displays app not found and exits 1", func() {
   127  				invalidAppName := "invalid-app-name"
   128  				session := helpers.CF("v3-start", invalidAppName)
   129  
   130  				Eventually(session.Err).Should(Say("App '%s' not found", invalidAppName))
   131  				Eventually(session).Should(Say("FAILED"))
   132  
   133  				Eventually(session).Should(Exit(1))
   134  			})
   135  		})
   136  	})
   137  })