github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/experimental/v3_create_app_command_test.go (about)

     1  package experimental
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  	. "github.com/onsi/gomega/ghttp"
    11  )
    12  
    13  var _ = Describe("v3-create-app 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-create-app", "--help")
    30  				Eventually(session).Should(Say("NAME:"))
    31  				Eventually(session).Should(Say("v3-create-app - Create a V3 App"))
    32  				Eventually(session).Should(Say("USAGE:"))
    33  				Eventually(session).Should(Say(`cf v3-create-app APP_NAME \[--app-type \(buildpack | docker\)\]`))
    34  				Eventually(session).Should(Say("OPTIONS:"))
    35  				Eventually(session).Should(Say(`--app-type\s+App lifecycle type to stage and run the app \(Default: buildpack\)`))
    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-create-app")
    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-create-app", 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("app type is not supported", func() {
    58  		It("tells the user that the app type is incorrect, prints help text, and exits 1", func() {
    59  			session := helpers.CF("v3-create-app", appName, "--app-type", "unknown-app-type")
    60  
    61  			Eventually(session.Err).Should(Say("Incorrect Usage: Invalid value `unknown-app-type' for option `--app-type'. Allowed values are: buildpack or docker"))
    62  			Eventually(session).Should(Say("NAME:"))
    63  			Eventually(session).Should(Exit(1))
    64  		})
    65  	})
    66  
    67  	When("the environment is not setup correctly", func() {
    68  		When("the v3 api version is lower than the minimum version", func() {
    69  			var server *Server
    70  
    71  			BeforeEach(func() {
    72  				server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion)
    73  			})
    74  
    75  			AfterEach(func() {
    76  				server.Close()
    77  			})
    78  
    79  			It("fails with error message that the minimum version is not met", func() {
    80  				session := helpers.CF("v3-create-app", appName)
    81  				Eventually(session).Should(Say("FAILED"))
    82  				Eventually(session.Err).Should(Say(`This command requires CF API version 3\.27\.0 or higher\.`))
    83  				Eventually(session).Should(Exit(1))
    84  			})
    85  		})
    86  
    87  		It("fails with the appropriate errors", func() {
    88  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-create-app", appName)
    89  		})
    90  	})
    91  
    92  	When("the environment is set up correctly", func() {
    93  		BeforeEach(func() {
    94  			helpers.SetupCF(orgName, spaceName)
    95  		})
    96  
    97  		AfterEach(func() {
    98  			helpers.QuickDeleteOrg(orgName)
    99  		})
   100  
   101  		When("the app does not exist", func() {
   102  			It("creates the app with default app type buildpack", func() {
   103  				session := helpers.CF("v3-create-app", appName)
   104  				userName, _ := helpers.GetCredentials()
   105  				Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   106  				Eventually(session).Should(Say("OK"))
   107  				Eventually(session).Should(Exit(0))
   108  
   109  				session = helpers.CF("app", appName)
   110  				Eventually(session).Should(Say("buildpacks:"))
   111  				Eventually(session).Should(Exit(0))
   112  			})
   113  
   114  			When("app type is specified", func() {
   115  				It("creates the app with the specified app type", func() {
   116  					session := helpers.CF("v3-create-app", appName, "--app-type", "docker")
   117  					userName, _ := helpers.GetCredentials()
   118  					Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   119  					Eventually(session).Should(Say("OK"))
   120  					Eventually(session).Should(Exit(0))
   121  
   122  					session = helpers.CF("app", appName)
   123  					Eventually(session).Should(Say("docker image:"))
   124  					Eventually(session).Should(Exit(0))
   125  				})
   126  			})
   127  		})
   128  
   129  		When("the app already exists", func() {
   130  			BeforeEach(func() {
   131  				Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0))
   132  			})
   133  
   134  			It("fails to create the app", func() {
   135  				session := helpers.CF("v3-create-app", appName)
   136  				userName, _ := helpers.GetCredentials()
   137  				Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   138  				Eventually(session.Err).Should(Say("App %s already exists", appName))
   139  				Eventually(session).Should(Say("OK"))
   140  				Eventually(session).Should(Exit(0))
   141  			})
   142  		})
   143  	})
   144  })