github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/experimental/v3_create_package_command_test.go (about)

     1  package experimental
     2  
     3  import (
     4  	"github.com/liamawhite/cli-with-i18n/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-package 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-package", "--help")
    29  				Eventually(session).Should(Say("NAME:"))
    30  				Eventually(session).Should(Say("v3-create-package - Uploads a V3 Package"))
    31  				Eventually(session).Should(Say("USAGE:"))
    32  				Eventually(session).Should(Say("cf v3-create-package APP_NAME \\[--docker-image \\[REGISTRY_HOST:PORT/\\]IMAGE\\[:TAG\\]\\]"))
    33  				Eventually(session).Should(Say("OPTIONS:"))
    34  				Eventually(session).Should(Say("--docker-image, -o\\s+Docker-image to be used \\(e.g. user/docker-image-name\\)"))
    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-package")
    43  
    44  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    45  			Eventually(session.Out).Should(Say("NAME:"))
    46  			Eventually(session).Should(Exit(1))
    47  		})
    48  	})
    49  
    50  	Context("when the environment is not setup correctly", func() {
    51  		Context("when no API endpoint is set", func() {
    52  			BeforeEach(func() {
    53  				helpers.UnsetAPI()
    54  			})
    55  
    56  			It("fails with no API endpoint set message", func() {
    57  				session := helpers.CF("v3-create-package", appName)
    58  				Eventually(session).Should(Say("FAILED"))
    59  				Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint."))
    60  				Eventually(session).Should(Exit(1))
    61  			})
    62  		})
    63  
    64  		Context("when the v3 api does not exist", func() {
    65  			var server *Server
    66  
    67  			BeforeEach(func() {
    68  				server = helpers.StartAndTargetServerWithoutV3API()
    69  			})
    70  
    71  			AfterEach(func() {
    72  				server.Close()
    73  			})
    74  
    75  			It("fails with error message that the minimum version is not met", func() {
    76  				session := helpers.CF("v3-create-package", appName)
    77  				Eventually(session).Should(Say("FAILED"))
    78  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
    79  				Eventually(session).Should(Exit(1))
    80  			})
    81  		})
    82  
    83  		Context("when the v3 api version is lower than the minimum version", func() {
    84  			var server *Server
    85  
    86  			BeforeEach(func() {
    87  				server = helpers.StartAndTargetServerWithV3Version("3.0.0")
    88  			})
    89  
    90  			AfterEach(func() {
    91  				server.Close()
    92  			})
    93  
    94  			It("fails with error message that the minimum version is not met", func() {
    95  				session := helpers.CF("v3-create-package", appName)
    96  				Eventually(session).Should(Say("FAILED"))
    97  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
    98  				Eventually(session).Should(Exit(1))
    99  			})
   100  		})
   101  
   102  		Context("when not logged in", func() {
   103  			BeforeEach(func() {
   104  				helpers.LogoutCF()
   105  			})
   106  
   107  			It("fails with not logged in message", func() {
   108  				session := helpers.CF("v3-create-package", appName)
   109  				Eventually(session).Should(Say("FAILED"))
   110  				Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in."))
   111  				Eventually(session).Should(Exit(1))
   112  			})
   113  		})
   114  
   115  		Context("when there is no org set", func() {
   116  			BeforeEach(func() {
   117  				helpers.LogoutCF()
   118  				helpers.LoginCF()
   119  			})
   120  
   121  			It("fails with no targeted org error message", func() {
   122  				session := helpers.CF("v3-create-package", appName)
   123  				Eventually(session.Out).Should(Say("FAILED"))
   124  				Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org."))
   125  				Eventually(session).Should(Exit(1))
   126  			})
   127  		})
   128  
   129  		Context("when there is no space set", func() {
   130  			BeforeEach(func() {
   131  				helpers.LogoutCF()
   132  				helpers.LoginCF()
   133  				helpers.TargetOrg(ReadOnlyOrg)
   134  			})
   135  
   136  			It("fails with no targeted space error message", func() {
   137  				session := helpers.CF("v3-create-package", appName)
   138  				Eventually(session.Out).Should(Say("FAILED"))
   139  				Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space."))
   140  				Eventually(session).Should(Exit(1))
   141  			})
   142  		})
   143  	})
   144  
   145  	Context("when the environment is set up correctly", func() {
   146  		BeforeEach(func() {
   147  			setupCF(orgName, spaceName)
   148  		})
   149  
   150  		AfterEach(func() {
   151  			helpers.QuickDeleteOrg(orgName)
   152  		})
   153  
   154  		Context("when the app does not exist", func() {
   155  			It("returns a not found error", func() {
   156  				session := helpers.CF("v3-create-package", appName)
   157  				userName, _ := helpers.GetCredentials()
   158  				Eventually(session).Should(Say("Uploading and creating bits package for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   159  				Eventually(session.Err).Should(Say("App %s not found", appName))
   160  				Eventually(session).Should(Say("FAILED"))
   161  				Eventually(session).Should(Exit(1))
   162  			})
   163  		})
   164  
   165  		Context("when the app exists", func() {
   166  			BeforeEach(func() {
   167  				Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0))
   168  			})
   169  
   170  			It("creates the package", func() {
   171  				session := helpers.CF("v3-create-package", appName)
   172  				userName, _ := helpers.GetCredentials()
   173  				Eventually(session).Should(Say("Uploading and creating bits package for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   174  				Eventually(session).Should(Say("package guid: %s", helpers.GUIDRegex))
   175  				Eventually(session).Should(Say("OK"))
   176  				Eventually(session).Should(Exit(0))
   177  			})
   178  
   179  			Context("when the --docker-image flag is provided", func() {
   180  				Context("when the docker-image exists", func() {
   181  					It("creates the package", func() {
   182  						session := helpers.CF("v3-create-package", appName, "--docker-image", PublicDockerImage)
   183  						userName, _ := helpers.GetCredentials()
   184  						Eventually(session).Should(Say("Creating docker package for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   185  						Eventually(session).Should(Say("package guid: %s", helpers.GUIDRegex))
   186  						Eventually(session).Should(Say("OK"))
   187  						Eventually(session).Should(Exit(0))
   188  					})
   189  				})
   190  			})
   191  		})
   192  	})
   193  })