github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/actor/pushaction/merge_and_validate_settings_and_manifest_test.go (about) 1 package pushaction_test 2 3 import ( 4 . "github.com/liamawhite/cli-with-i18n/actor/pushaction" 5 "github.com/liamawhite/cli-with-i18n/types" 6 "github.com/liamawhite/cli-with-i18n/util/manifest" 7 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/ginkgo/extensions/table" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("MergeAndValidateSettingsAndManifest", func() { 14 var ( 15 actor *Actor 16 cmdSettings CommandLineSettings 17 18 currentDirectory string 19 ) 20 21 BeforeEach(func() { 22 actor = NewActor(nil, nil) 23 currentDirectory = getCurrentDir() 24 }) 25 26 Context("when only passed command line settings", func() { 27 BeforeEach(func() { 28 cmdSettings = CommandLineSettings{ 29 CurrentDirectory: currentDirectory, 30 DockerImage: "some-image", 31 Name: "some-app", 32 } 33 }) 34 35 It("returns a manifest made from the command line settings", func() { 36 manifests, err := actor.MergeAndValidateSettingsAndManifests(cmdSettings, nil) 37 Expect(err).ToNot(HaveOccurred()) 38 Expect(manifests).To(Equal([]manifest.Application{{ 39 DockerImage: "some-image", 40 Name: "some-app", 41 Path: currentDirectory, 42 }})) 43 }) 44 }) 45 46 Context("when passed command line settings and a single manifest application", func() { 47 var ( 48 apps []manifest.Application 49 mergedApps []manifest.Application 50 executeErr error 51 ) 52 53 BeforeEach(func() { 54 cmdSettings = CommandLineSettings{ 55 CurrentDirectory: currentDirectory, 56 Name: "steve", 57 } 58 59 apps = []manifest.Application{ 60 {Name: "app-1"}, 61 } 62 }) 63 64 JustBeforeEach(func() { 65 mergedApps, executeErr = actor.MergeAndValidateSettingsAndManifests(cmdSettings, apps) 66 }) 67 68 It("merges command line settings and manifest apps", func() { 69 Expect(executeErr).ToNot(HaveOccurred()) 70 71 Expect(mergedApps).To(ConsistOf( 72 manifest.Application{ 73 Name: "steve", 74 Path: currentDirectory, 75 }, 76 )) 77 }) 78 }) 79 80 Context("when passed command line settings and multiple manifest applications", func() { 81 var ( 82 apps []manifest.Application 83 mergedApps []manifest.Application 84 executeErr error 85 ) 86 87 BeforeEach(func() { 88 cmdSettings = CommandLineSettings{ 89 CurrentDirectory: currentDirectory, 90 } 91 92 apps = []manifest.Application{ 93 {Name: "app-1"}, 94 {Name: "app-2"}, 95 } 96 }) 97 98 JustBeforeEach(func() { 99 mergedApps, executeErr = actor.MergeAndValidateSettingsAndManifests(cmdSettings, apps) 100 }) 101 102 It("merges command line settings and manifest apps", func() { 103 Expect(executeErr).ToNot(HaveOccurred()) 104 105 Expect(mergedApps).To(ConsistOf( 106 manifest.Application{ 107 Name: "app-1", 108 Path: currentDirectory, 109 }, 110 manifest.Application{ 111 Name: "app-2", 112 Path: currentDirectory, 113 }, 114 )) 115 }) 116 117 Context("when CommandLineSettings specify an app in the manifests", func() { 118 Context("when the app exists in the manifest", func() { 119 BeforeEach(func() { 120 cmdSettings.Name = "app-1" 121 }) 122 123 It("returns just the specified app manifest", func() { 124 Expect(executeErr).ToNot(HaveOccurred()) 125 126 Expect(mergedApps).To(ConsistOf( 127 manifest.Application{ 128 Name: "app-1", 129 Path: currentDirectory, 130 }, 131 )) 132 }) 133 }) 134 135 Context("when the app does *not* exist in the manifest", func() { 136 BeforeEach(func() { 137 cmdSettings.Name = "app-4" 138 }) 139 140 It("returns just the specified app manifest", func() { 141 Expect(executeErr).To(MatchError(AppNotFoundInManifestError{Name: "app-4"})) 142 }) 143 }) 144 }) 145 }) 146 147 Describe("defaulting values", func() { 148 var ( 149 apps []manifest.Application 150 mergedApps []manifest.Application 151 executeErr error 152 ) 153 154 BeforeEach(func() { 155 cmdSettings = CommandLineSettings{ 156 CurrentDirectory: currentDirectory, 157 } 158 159 apps = []manifest.Application{ 160 {Name: "app-1"}, 161 {Name: "app-2"}, 162 } 163 }) 164 165 JustBeforeEach(func() { 166 mergedApps, executeErr = actor.MergeAndValidateSettingsAndManifests(cmdSettings, apps) 167 }) 168 169 Context("when HealthCheckType is set to http and no endpoint is set", func() { 170 BeforeEach(func() { 171 apps[0].HealthCheckType = "http" 172 apps[1].HealthCheckType = "http" 173 apps[1].HealthCheckHTTPEndpoint = "/banana" 174 }) 175 176 It("sets health-check-http-endpoint to '/'", func() { 177 Expect(executeErr).ToNot(HaveOccurred()) 178 Expect(mergedApps[0].HealthCheckHTTPEndpoint).To(Equal("/")) 179 Expect(mergedApps[1].HealthCheckHTTPEndpoint).To(Equal("/banana")) 180 }) 181 }) 182 }) 183 184 DescribeTable("validation errors", 185 func(settings CommandLineSettings, apps []manifest.Application, expectedErr error) { 186 _, err := actor.MergeAndValidateSettingsAndManifests(settings, apps) 187 Expect(err).To(MatchError(expectedErr)) 188 }, 189 190 Entry("MissingNameError", CommandLineSettings{}, nil, MissingNameError{}), 191 Entry("MissingNameError", CommandLineSettings{}, []manifest.Application{{}}, MissingNameError{}), 192 Entry("NonexistentAppPathError", CommandLineSettings{Name: "some-name", ProvidedAppPath: "does-not-exist"}, nil, NonexistentAppPathError{Path: "does-not-exist"}), 193 Entry("NonexistentAppPathError", CommandLineSettings{}, []manifest.Application{{Name: "some-name", Path: "does-not-exist"}}, NonexistentAppPathError{Path: "does-not-exist"}), 194 Entry("CommandLineOptionsWithMultipleAppsError", 195 CommandLineSettings{Buildpack: types.FilteredString{IsSet: true}}, 196 []manifest.Application{{Name: "some-name-1"}, {Name: "some-name-2"}}, 197 CommandLineOptionsWithMultipleAppsError{}), 198 Entry("CommandLineOptionsWithMultipleAppsError", 199 CommandLineSettings{Command: types.FilteredString{IsSet: true}}, 200 []manifest.Application{{Name: "some-name-1"}, {Name: "some-name-2"}}, CommandLineOptionsWithMultipleAppsError{}), 201 Entry("CommandLineOptionsWithMultipleAppsError", CommandLineSettings{DiskQuota: 4}, []manifest.Application{{Name: "some-name-1"}, {Name: "some-name-2"}}, CommandLineOptionsWithMultipleAppsError{}), 202 Entry("CommandLineOptionsWithMultipleAppsError", CommandLineSettings{DockerImage: "some-docker-image"}, []manifest.Application{{Name: "some-name-1"}, {Name: "some-name-2"}}, CommandLineOptionsWithMultipleAppsError{}), 203 Entry("CommandLineOptionsWithMultipleAppsError", CommandLineSettings{HealthCheckTimeout: 4}, []manifest.Application{{Name: "some-name-1"}, {Name: "some-name-2"}}, CommandLineOptionsWithMultipleAppsError{}), 204 Entry("CommandLineOptionsWithMultipleAppsError", CommandLineSettings{HealthCheckType: "http"}, []manifest.Application{{Name: "some-name-1"}, {Name: "some-name-2"}}, CommandLineOptionsWithMultipleAppsError{}), 205 Entry("CommandLineOptionsWithMultipleAppsError", CommandLineSettings{Instances: types.NullInt{IsSet: true}}, []manifest.Application{{Name: "some-name-1"}, {Name: "some-name-2"}}, CommandLineOptionsWithMultipleAppsError{}), 206 Entry("CommandLineOptionsWithMultipleAppsError", CommandLineSettings{Memory: 4}, []manifest.Application{{Name: "some-name-1"}, {Name: "some-name-2"}}, CommandLineOptionsWithMultipleAppsError{}), 207 Entry("CommandLineOptionsWithMultipleAppsError", CommandLineSettings{ProvidedAppPath: "some-path"}, []manifest.Application{{Name: "some-name-1"}, {Name: "some-name-2"}}, CommandLineOptionsWithMultipleAppsError{}), 208 Entry("CommandLineOptionsWithMultipleAppsError", CommandLineSettings{StackName: "some-stackname"}, []manifest.Application{{Name: "some-name-1"}, {Name: "some-name-2"}}, CommandLineOptionsWithMultipleAppsError{}), 209 ) 210 })