github.com/sleungcy/cli@v7.1.0+incompatible/actor/v7pushaction/handle_docker_image_override_test.go (about) 1 package v7pushaction_test 2 3 import ( 4 "code.cloudfoundry.org/cli/command/translatableerror" 5 "code.cloudfoundry.org/cli/util/manifestparser" 6 7 . "code.cloudfoundry.org/cli/actor/v7pushaction" 8 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("HandleDockerImageOverride", func() { 14 var ( 15 originalManifest manifestparser.Manifest 16 transformedManifest manifestparser.Manifest 17 overrides FlagOverrides 18 executeErr error 19 ) 20 21 BeforeEach(func() { 22 originalManifest = manifestparser.Manifest{} 23 overrides = FlagOverrides{} 24 }) 25 26 JustBeforeEach(func() { 27 transformedManifest, executeErr = HandleDockerImageOverride(originalManifest, overrides) 28 }) 29 30 When("docker image flag is set", func() { 31 When("there is a single app in the manifest without any docker info specified", func() { 32 BeforeEach(func() { 33 overrides.DockerImage = "some-docker-image" 34 35 originalManifest.Applications = []manifestparser.Application{ 36 {}, 37 } 38 }) 39 40 It("will populate the docker image in the manifest with the provided flag value", func() { 41 Expect(executeErr).To(Not(HaveOccurred())) 42 Expect(transformedManifest.Applications).To(ConsistOf( 43 manifestparser.Application{ 44 Docker: &manifestparser.Docker{ 45 Image: "some-docker-image", 46 }, 47 }, 48 )) 49 }) 50 }) 51 52 When("there is a single app in the manifest with a docker image specified", func() { 53 BeforeEach(func() { 54 overrides.DockerImage = "some-docker-image" 55 56 originalManifest.Applications = []manifestparser.Application{ 57 { 58 Docker: &manifestparser.Docker{Image: "old-docker-image"}, 59 }, 60 } 61 }) 62 63 It("will override the docker image in the manifest with the provided flag value", func() { 64 Expect(executeErr).To(Not(HaveOccurred())) 65 Expect(transformedManifest.Applications).To(ConsistOf( 66 manifestparser.Application{ 67 Docker: &manifestparser.Docker{ 68 Image: "some-docker-image", 69 }, 70 }, 71 )) 72 }) 73 }) 74 75 When("when buildpacks are set in the manifest", func() { 76 BeforeEach(func() { 77 overrides.DockerImage = "some-docker-image" 78 79 originalManifest.Applications = []manifestparser.Application{ 80 { 81 Name: "some-app", 82 RemainingManifestFields: map[string]interface{}{"buildpacks": []string{"buildpack-1"}}, 83 }, 84 } 85 }) 86 87 It("returns an error", func() { 88 Expect(executeErr).To(MatchError(translatableerror.ArgumentManifestMismatchError{ 89 Arg: "--docker-image, -o", 90 ManifestProperty: "buildpacks", 91 })) 92 }) 93 }) 94 95 When("a path is set in the manifest", func() { 96 BeforeEach(func() { 97 overrides.DockerImage = "some-docker-image" 98 99 originalManifest.Applications = []manifestparser.Application{ 100 { 101 Name: "some-app", 102 Path: "/some/path", 103 }, 104 } 105 }) 106 107 It("returns an error", func() { 108 Expect(executeErr).To(MatchError(translatableerror.ArgumentManifestMismatchError{ 109 Arg: "--docker-image, -o", 110 ManifestProperty: "path", 111 })) 112 }) 113 }) 114 115 When("there are multiple apps in the manifest", func() { 116 BeforeEach(func() { 117 overrides.DockerImage = "some-docker-image" 118 119 originalManifest.Applications = []manifestparser.Application{ 120 {}, 121 {}, 122 } 123 }) 124 125 It("returns an error", func() { 126 Expect(executeErr).To(MatchError(translatableerror.CommandLineArgsWithMultipleAppsError{})) 127 }) 128 }) 129 }) 130 })