github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/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  	. "github.com/onsi/gomega/ghttp"
    10  )
    11  
    12  var _ = Describe("v3-create-app command", func() {
    13  	var (
    14  		orgName   string
    15  		spaceName string
    16  		appName   string
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		orgName = helpers.NewOrgName()
    21  		spaceName = helpers.NewSpaceName()
    22  		appName = helpers.PrefixedRandomName("app")
    23  	})
    24  
    25  	Describe("help", func() {
    26  		Context("when --help flag is set", func() {
    27  			It("Displays command usage to output", func() {
    28  				session := helpers.CF("v3-create-app", "--help")
    29  				Eventually(session).Should(Say("NAME:"))
    30  				Eventually(session).Should(Say("v3-create-app - Create a V3 App"))
    31  				Eventually(session).Should(Say("USAGE:"))
    32  				Eventually(session).Should(Say("cf v3-create-app APP_NAME \\[--app-type \\(buildpack | docker\\)\\]"))
    33  				Eventually(session).Should(Say("OPTIONS:"))
    34  				Eventually(session).Should(Say("--app-type\\s+App lifecycle type to stage and run the app \\(Default: buildpack\\)"))
    35  				Eventually(session).Should(Exit(0))
    36  			})
    37  		})
    38  	})
    39  
    40  	Context("when the app name is not provided", func() {
    41  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    42  			session := helpers.CF("v3-create-app")
    43  
    44  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    45  			Eventually(session).Should(Say("NAME:"))
    46  			Eventually(session).Should(Exit(1))
    47  		})
    48  	})
    49  
    50  	It("displays the experimental warning", func() {
    51  		session := helpers.CF("v3-create-app", appName)
    52  		Eventually(session).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    53  		Eventually(session).Should(Exit())
    54  	})
    55  
    56  	Context("when app type is not supported", func() {
    57  		It("tells the user that the app type is incorrect, prints help text, and exits 1", func() {
    58  			session := helpers.CF("v3-create-app", appName, "--app-type", "unknown-app-type")
    59  
    60  			Eventually(session.Err).Should(Say("Incorrect Usage: Invalid value `unknown-app-type' for option `--app-type'. Allowed values are: buildpack or docker"))
    61  			Eventually(session).Should(Say("NAME:"))
    62  			Eventually(session).Should(Exit(1))
    63  		})
    64  	})
    65  
    66  	Context("when the environment is not setup correctly", func() {
    67  		Context("when no API endpoint is set", func() {
    68  			BeforeEach(func() {
    69  				helpers.UnsetAPI()
    70  			})
    71  
    72  			It("fails with no API endpoint set message", func() {
    73  				session := helpers.CF("v3-create-app", appName)
    74  				Eventually(session).Should(Say("FAILED"))
    75  				Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint."))
    76  				Eventually(session).Should(Exit(1))
    77  			})
    78  		})
    79  
    80  		Context("when the v3 api does not exist", func() {
    81  			var server *Server
    82  
    83  			BeforeEach(func() {
    84  				server = helpers.StartAndTargetServerWithoutV3API()
    85  			})
    86  
    87  			AfterEach(func() {
    88  				server.Close()
    89  			})
    90  
    91  			It("fails with error message that the minimum version is not met", func() {
    92  				session := helpers.CF("v3-create-app", appName)
    93  				Eventually(session).Should(Say("FAILED"))
    94  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
    95  				Eventually(session).Should(Exit(1))
    96  			})
    97  		})
    98  
    99  		Context("when the v3 api version is lower than the minimum version", func() {
   100  			var server *Server
   101  
   102  			BeforeEach(func() {
   103  				server = helpers.StartAndTargetServerWithV3Version("3.0.0")
   104  			})
   105  
   106  			AfterEach(func() {
   107  				server.Close()
   108  			})
   109  
   110  			It("fails with error message that the minimum version is not met", func() {
   111  				session := helpers.CF("v3-create-app", appName)
   112  				Eventually(session).Should(Say("FAILED"))
   113  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
   114  				Eventually(session).Should(Exit(1))
   115  			})
   116  		})
   117  
   118  		Context("when not logged in", func() {
   119  			BeforeEach(func() {
   120  				helpers.LogoutCF()
   121  			})
   122  
   123  			It("fails with not logged in message", func() {
   124  				session := helpers.CF("v3-create-app", appName)
   125  				Eventually(session).Should(Say("FAILED"))
   126  				Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in."))
   127  				Eventually(session).Should(Exit(1))
   128  			})
   129  		})
   130  
   131  		Context("when there is no org set", func() {
   132  			BeforeEach(func() {
   133  				helpers.LogoutCF()
   134  				helpers.LoginCF()
   135  			})
   136  
   137  			It("fails with no targeted org error message", func() {
   138  				session := helpers.CF("v3-create-app", appName)
   139  				Eventually(session).Should(Say("FAILED"))
   140  				Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org."))
   141  				Eventually(session).Should(Exit(1))
   142  			})
   143  		})
   144  
   145  		Context("when there is no space set", func() {
   146  			BeforeEach(func() {
   147  				helpers.LogoutCF()
   148  				helpers.LoginCF()
   149  				helpers.TargetOrg(ReadOnlyOrg)
   150  			})
   151  
   152  			It("fails with no targeted space error message", func() {
   153  				session := helpers.CF("v3-create-app", appName)
   154  				Eventually(session).Should(Say("FAILED"))
   155  				Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space."))
   156  				Eventually(session).Should(Exit(1))
   157  			})
   158  		})
   159  	})
   160  
   161  	Context("when the environment is set up correctly", func() {
   162  		BeforeEach(func() {
   163  			setupCF(orgName, spaceName)
   164  		})
   165  
   166  		AfterEach(func() {
   167  			helpers.QuickDeleteOrg(orgName)
   168  		})
   169  
   170  		Context("when the app does not exist", func() {
   171  			It("creates the app with default app type buildpack", func() {
   172  				session := helpers.CF("v3-create-app", appName)
   173  				userName, _ := helpers.GetCredentials()
   174  				Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   175  				Eventually(session).Should(Say("OK"))
   176  				Eventually(session).Should(Exit(0))
   177  
   178  				session = helpers.CF("v3-app", appName)
   179  				Eventually(session).Should(Say("buildpacks:"))
   180  				Eventually(session).Should(Exit(0))
   181  			})
   182  
   183  			Context("when app type is specified", func() {
   184  				It("creates the app with the specified app type", func() {
   185  					session := helpers.CF("v3-create-app", appName, "--app-type", "docker")
   186  					userName, _ := helpers.GetCredentials()
   187  					Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   188  					Eventually(session).Should(Say("OK"))
   189  					Eventually(session).Should(Exit(0))
   190  
   191  					session = helpers.CF("v3-app", appName)
   192  					Eventually(session).Should(Say("docker image:"))
   193  					Eventually(session).Should(Exit(0))
   194  				})
   195  			})
   196  		})
   197  
   198  		Context("when the app already exists", func() {
   199  			BeforeEach(func() {
   200  				Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0))
   201  			})
   202  
   203  			It("fails to create the app", func() {
   204  				session := helpers.CF("v3-create-app", appName)
   205  				userName, _ := helpers.GetCredentials()
   206  				Eventually(session).Should(Say("Creating V3 app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   207  				Eventually(session.Err).Should(Say("App %s already exists", appName))
   208  				Eventually(session).Should(Say("OK"))
   209  				Eventually(session).Should(Exit(0))
   210  			})
   211  		})
   212  	})
   213  })