github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/push/combination_manifest_and_flag_test.go (about)

     1  package push
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  	"regexp"
     8  
     9  	"code.cloudfoundry.org/cli/integration/helpers"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/ginkgo/extensions/table"
    12  	. "github.com/onsi/gomega"
    13  	. "github.com/onsi/gomega/gbytes"
    14  	. "github.com/onsi/gomega/gexec"
    15  )
    16  
    17  var _ = Describe("push with a simple manifest and flags", func() {
    18  	DescribeTable("manifest conflicts with push flags",
    19  		func(manifest map[string]interface{}, expectedOutput string, flags ...string) {
    20  			helpers.WithHelloWorldApp(func(dir string) {
    21  				helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), manifest)
    22  
    23  				pushCommandAndFlags := append([]string{PushCommandName}, flags...)
    24  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, pushCommandAndFlags...)
    25  				Eventually(session.Err).Should(Say(regexp.QuoteMeta(expectedOutput)))
    26  				Eventually(session).Should(Exit(1))
    27  			})
    28  		},
    29  
    30  		Entry("Manifest buildpacks with docker flag",
    31  			map[string]interface{}{
    32  				"applications": []map[string]interface{}{
    33  					{
    34  						"name":       "app-name",
    35  						"buildpacks": []string{"ruby_buildpack"},
    36  					},
    37  				},
    38  			},
    39  			"Incorrect Usage: The flag option --docker-image, -o cannot be used with the manifest property buildpacks",
    40  			"--docker-image", "docker",
    41  		),
    42  
    43  		Entry("Manifest path with docker flag",
    44  			map[string]interface{}{
    45  				"applications": []map[string]interface{}{
    46  					{
    47  						"name": "app-name",
    48  						"path": "~",
    49  					},
    50  				},
    51  			},
    52  			"Incorrect Usage: The flag option --docker-image, -o cannot be used with the manifest property path",
    53  			"--docker-image", "docker",
    54  		),
    55  
    56  		Entry("Manifest docker with droplet flag",
    57  			map[string]interface{}{
    58  				"applications": []map[string]interface{}{
    59  					{
    60  						"name":   "app-name",
    61  						"docker": map[string]interface{}{"image": "docker"},
    62  					},
    63  				},
    64  			},
    65  			"Incorrect Usage: The flag option --droplet cannot be used with the manifest property docker",
    66  			"--droplet", os.TempDir(),
    67  		),
    68  
    69  		Entry("Manifest buildpacks with droplet flag",
    70  			map[string]interface{}{
    71  				"applications": []map[string]interface{}{
    72  					{
    73  						"name":       "app-name",
    74  						"buildpacks": []string{"ruby_buildpack"},
    75  					},
    76  				},
    77  			},
    78  			"Incorrect Usage: The flag option --droplet cannot be used with the manifest property buildpacks",
    79  			"--droplet", os.TempDir(),
    80  		),
    81  
    82  		Entry("Manifest path with droplet flag",
    83  			map[string]interface{}{
    84  				"applications": []map[string]interface{}{
    85  					{
    86  						"name": "app-name",
    87  						"path": os.TempDir(),
    88  					},
    89  				},
    90  			},
    91  			"Incorrect Usage: The flag option --droplet cannot be used with the manifest property path",
    92  			"--droplet", os.TempDir(),
    93  		),
    94  
    95  		Entry("Manifest docker with buildpacks flag",
    96  			map[string]interface{}{
    97  				"applications": []map[string]interface{}{
    98  					{
    99  						"name":   "app-name",
   100  						"docker": map[string]interface{}{"image": "docker"},
   101  					},
   102  				},
   103  			},
   104  			"Incorrect Usage: The flag option --buildpack, -b cannot be used with the manifest property docker",
   105  			"-b", "ruby_buildpack",
   106  		),
   107  
   108  		Entry("Manifest docker with path flag",
   109  			map[string]interface{}{
   110  				"applications": []map[string]interface{}{
   111  					{
   112  						"name":   "app-name",
   113  						"docker": map[string]interface{}{"image": "docker"},
   114  					},
   115  				},
   116  			},
   117  			"Incorrect Usage: The flag option --path, -p cannot be used with the manifest property docker",
   118  			"-p", os.TempDir(),
   119  		),
   120  	)
   121  
   122  	When("pushing multiple apps from the manifest", func() {
   123  		Context("manifest contains multiple apps and '--no-start' is provided", func() {
   124  			var appName1, appName2 string
   125  
   126  			BeforeEach(func() {
   127  				Skip("After #162558994 has been completed")
   128  				appName1 = helpers.NewAppName()
   129  				appName2 = helpers.NewAppName()
   130  			})
   131  
   132  			It("does not start the apps", func() {
   133  				helpers.WithHelloWorldApp(func(dir string) {
   134  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   135  						"applications": []map[string]string{
   136  							{"name": appName1},
   137  							{"name": appName2},
   138  						},
   139  					})
   140  
   141  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   142  					Eventually(session).Should(Say(`Applying manifest\.\.\.`))
   143  					Eventually(session).Should(Say(`name:\s+%s`, appName1))
   144  					Eventually(session).Should(Say(`requested state:\s+stopped`))
   145  					Eventually(session).Should(Say(`name:\s+%s`, appName2))
   146  					Eventually(session).Should(Say(`requested state:\s+stopped`))
   147  					Eventually(session).Should(Exit(0))
   148  				})
   149  			})
   150  		})
   151  
   152  		Context("manifest contains multiple apps and a '-p' is provided", func() {
   153  			var tempDir string
   154  
   155  			BeforeEach(func() {
   156  				var err error
   157  				tempDir, err = ioutil.TempDir("", "combination-manifest-with-p")
   158  				Expect(err).ToNot(HaveOccurred())
   159  
   160  				helpers.WriteManifest(filepath.Join(tempDir, "manifest.yml"), map[string]interface{}{
   161  					"applications": []map[string]string{
   162  						{
   163  							"name": "name-1",
   164  						},
   165  						{
   166  							"name": "name-2",
   167  						},
   168  					},
   169  				})
   170  			})
   171  
   172  			AfterEach(func() {
   173  				Expect(os.RemoveAll(tempDir)).ToNot(HaveOccurred())
   174  			})
   175  
   176  			It("returns an error", func() {
   177  				helpers.WithHelloWorldApp(func(dir string) {
   178  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: tempDir}, PushCommandName, "-p", dir)
   179  					Eventually(session.Err).Should(Say(regexp.QuoteMeta("Incorrect Usage: Command line flags (except -f and --no-start) cannot be applied when pushing multiple apps from a manifest file.")))
   180  					Eventually(session).Should(Exit(1))
   181  				})
   182  			})
   183  		})
   184  
   185  		DescribeTable("errors when any flag (except for -f and --no-start) is specified",
   186  			func(flags ...string) {
   187  				helpers.WithHelloWorldApp(func(dir string) {
   188  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   189  						"applications": []map[string]string{
   190  							{"name": "some-app"},
   191  							{"name": "some-other-app"},
   192  						},
   193  					})
   194  
   195  					args := append([]string{PushCommandName}, flags...)
   196  					session := helpers.CustomCF(helpers.CFEnv{
   197  						WorkingDirectory: dir,
   198  						EnvVars:          map[string]string{"CF_DOCKER_PASSWORD": "some-password"},
   199  					}, args...)
   200  					Eventually(session.Err).Should(Say(regexp.QuoteMeta("Incorrect Usage: Command line flags (except -f and --no-start) cannot be applied when pushing multiple apps from a manifest file.")))
   201  					Eventually(session).Should(Exit(1))
   202  				})
   203  			},
   204  			Entry("buildpack", "-b", "somethin"),
   205  			Entry("disk", "-k", "100M"),
   206  			Entry("docker image", "-o", "something"),
   207  			Entry("docker image and username", "-o", "something", "--docker-username", "something"),
   208  			Entry("health check timeout", "-t", "10"),
   209  			Entry("health check type", "-u", "port"),
   210  			Entry("instances", "-i", "10"),
   211  			Entry("memory", "-m", "100M"),
   212  			Entry("no route", "--no-route"),
   213  			Entry("stack", "-s", "something"),
   214  		)
   215  	})
   216  
   217  })