github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/experimental/v3_create_app_command_test.go (about)

     1  package experimental
     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("v3-create-app command", func() {
    12  	var (
    13  		orgName   string
    14  		spaceName string
    15  		appName   string
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		orgName = helpers.NewOrgName()
    20  		spaceName = helpers.NewSpaceName()
    21  		appName = helpers.PrefixedRandomName("app")
    22  	})
    23  
    24  	Describe("help", func() {
    25  		When("--help flag is set", func() {
    26  			It("Displays command usage to output", func() {
    27  				session := helpers.CF("v3-create-app", "--help")
    28  				Eventually(session).Should(Say("NAME:"))
    29  				Eventually(session).Should(Say("v3-create-app - Create a V3 App"))
    30  				Eventually(session).Should(Say("USAGE:"))
    31  				Eventually(session).Should(Say(`cf v3-create-app APP_NAME \[--app-type \(buildpack | docker\)\]`))
    32  				Eventually(session).Should(Say("OPTIONS:"))
    33  				Eventually(session).Should(Say(`--app-type\s+App lifecycle type to stage and run the app \(Default: buildpack\)`))
    34  				Eventually(session).Should(Exit(0))
    35  			})
    36  		})
    37  	})
    38  
    39  	When("the app name is not provided", func() {
    40  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    41  			session := helpers.CF("v3-create-app")
    42  
    43  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    44  			Eventually(session).Should(Say("NAME:"))
    45  			Eventually(session).Should(Exit(1))
    46  		})
    47  	})
    48  
    49  	It("displays the experimental warning", func() {
    50  		session := helpers.CF("v3-create-app", appName)
    51  		Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    52  		Eventually(session).Should(Exit())
    53  	})
    54  
    55  	When("app type is not supported", func() {
    56  		It("tells the user that the app type is incorrect, prints help text, and exits 1", func() {
    57  			session := helpers.CF("v3-create-app", appName, "--app-type", "unknown-app-type")
    58  
    59  			Eventually(session.Err).Should(Say("Incorrect Usage: Invalid value `unknown-app-type' for option `--app-type'. Allowed values are: buildpack or docker"))
    60  			Eventually(session).Should(Say("NAME:"))
    61  			Eventually(session).Should(Exit(1))
    62  		})
    63  	})
    64  
    65  	When("the environment is not setup correctly", func() {
    66  		It("fails with the appropriate errors", func() {
    67  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-create-app", appName)
    68  		})
    69  	})
    70  
    71  	When("the environment is set up correctly", func() {
    72  		BeforeEach(func() {
    73  			helpers.SetupCF(orgName, spaceName)
    74  		})
    75  
    76  		AfterEach(func() {
    77  			helpers.QuickDeleteOrg(orgName)
    78  		})
    79  
    80  		When("the app does not exist", func() {
    81  			It("creates the app with default app type buildpack", func() {
    82  				session := helpers.CF("v3-create-app", appName)
    83  				userName, _ := helpers.GetCredentials()
    84  				Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
    85  				Eventually(session).Should(Say("OK"))
    86  				Eventually(session).Should(Exit(0))
    87  
    88  				session = helpers.CF("app", appName)
    89  				Eventually(session).Should(Say("buildpacks:"))
    90  				Eventually(session).Should(Exit(0))
    91  			})
    92  
    93  			When("app type is specified", func() {
    94  				It("creates the app with the specified app type", func() {
    95  					session := helpers.CF("v3-create-app", appName, "--app-type", "docker")
    96  					userName, _ := helpers.GetCredentials()
    97  					Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
    98  					Eventually(session).Should(Say("OK"))
    99  					Eventually(session).Should(Exit(0))
   100  
   101  					session = helpers.CF("app", appName)
   102  					Eventually(session).Should(Say("docker image:"))
   103  					Eventually(session).Should(Exit(0))
   104  				})
   105  			})
   106  		})
   107  
   108  		When("the app already exists", func() {
   109  			BeforeEach(func() {
   110  				Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0))
   111  			})
   112  
   113  			It("fails to create the app", func() {
   114  				session := helpers.CF("v3-create-app", appName)
   115  				userName, _ := helpers.GetCredentials()
   116  				Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   117  				Eventually(session.Err).Should(Say("App %s already exists", appName))
   118  				Eventually(session).Should(Say("OK"))
   119  				Eventually(session).Should(Exit(0))
   120  			})
   121  		})
   122  	})
   123  })