Skip to content

Commit

Permalink
[UPDATE] errors, add more tests, throw error when someone pass a wild…
Browse files Browse the repository at this point in the history
…card without legacy push
  • Loading branch information
HappyTobi committed Nov 26, 2019
1 parent d9e8d02 commit a943548
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 13 deletions.
13 changes: 10 additions & 3 deletions arguments/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ var (
//ErrNoArgument error when zero-downtime-push without a argument called
ErrNoArgument = errors.New("no valid argument found, use --help / -h for more information")
//ErrNoManifest error when manifes on push application was not found
ErrNoManifest = errors.New("a manifest is required to push this application")
ErrNoManifest = errors.New("a application manifest is required to push an application")
//ErrWrongEnvFormat error when env files was not in right format
ErrWrongEnvFormat = errors.New("--var would be in wrong format, use the vars like key=value")
ErrWrongEnvFormat = errors.New("environment variables passed in wrong format, pass the variables like key=value")
//ErrWrongCombination error when legacy push is used with health check options
ErrWrongCombination = errors.New("--legacy-push and health check options couldn't be combined")
//ErrWrongDockerCombination error when private docker image repo will be pushed without a pass
ErrWrongPrivateDockerRepoCombination = errors.New("--docker-username have to be used in combination with env CF_DOCKER_PASSWORD and --docker-image")
//Error manifest error when a wildcard was in the path directive
ErrNoWildcardSupport = errors.New("wildcard expressions within the path directive in the application manifest are not supported - delete this path directive and pass the artifact path by using the -p option")
)

// ParseArgs parses the command line arguments
Expand All @@ -76,7 +78,7 @@ func ParseArgs(args []string) (*ParserArguments, error) {
flags.StringVar(&pta.Process, "process", "", "use health check type process")
flags.BoolVar(&pta.ShowLogs, "show-app-log", false, "tail and show application log during application start")
flags.BoolVar(&pta.ShowCrashLogs, "show-crash-log", false, "Show recent logs when applications crashes while the deployment")
flags.StringVar(&pta.VenerableAction, "venerable-action", "delete", "option to delete,stop,none application action on vendor app- default is delete")
flags.StringVar(&pta.VenerableAction, "venerable-action", "delete", "option to delete,stop,none application action on venerable app default is delete")
flags.Var(&envs, "env", "Variable key value pair for adding dynamic environment variables; can specify multiple times")
flags.BoolVar(&pta.LegacyPush, "legacy-push", false, "use legacy push instead of new v3 api")
flags.BoolVar(&pta.NoRoute, "no-route", false, "deploy new application without adding routes")
Expand Down Expand Up @@ -115,6 +117,11 @@ func ParseArgs(args []string) (*ParserArguments, error) {
if err != nil {
return pta, err //ErrManifest
}

if strings.ContainsAny(parsedManifest.ApplicationManifests[0].Path, "*") && pta.LegacyPush == false {
return pta, ErrNoWildcardSupport
}

pta.Manifest = parsedManifest

//check if a docker image shouldbe pushed and verify passed args combination
Expand Down
51 changes: 50 additions & 1 deletion arguments/arguments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ var _ = Describe("Flag Parsing", func() {
Expect(parsedArguments.NoRoute).To(Equal(false))
})

It("parses a all args without venerable action", func() {
parsedArguments, err := ParseArgs(
[]string{
"zero-downtime-push",
"appname",
"-f", "../fixtures/manifest.yml",
"-p", "app-path",
"-s", "stack-name",
},
)
Expect(err).ToNot(HaveOccurred())

Expect(parsedArguments.AppName).To(Equal("appname"))
Expect(parsedArguments.ManifestPath).To(Equal("../fixtures/manifest.yml"))
Expect(parsedArguments.AppPath).To(Equal("app-path"))
Expect(parsedArguments.StackName).To(Equal("stack-name"))
Expect(parsedArguments.VenerableAction).Should(Equal("delete"))
Expect(parsedArguments.ShowLogs).To(Equal(false))
Expect(parsedArguments.ShowCrashLogs).To(Equal(false))
Expect(parsedArguments.NoRoute).To(Equal(false))
Expect(parsedArguments.Timeout).To(Equal(2))
Expect(parsedArguments.InvocationTimeout).To(Equal(-1))
Expect(parsedArguments.Process).To(Equal(""))
Expect(parsedArguments.HealthCheckType).To(Equal("http"))
Expect(parsedArguments.HealthCheckHTTPEndpoint).To(Equal("/health"))
})

It("parses a all args without timeout", func() {
parsedArguments, err := ParseArgs(
[]string{
Expand Down Expand Up @@ -211,7 +238,6 @@ var _ = Describe("Flag Parsing", func() {
Expect(parsedArguments.NoRoute).Should(Equal(true))
Expect(parsedArguments.VenerableAction).Should(Equal("none"))
})

})

var _ = Describe("Deprecated flag parsing", func() {
Expand All @@ -231,4 +257,27 @@ var _ = Describe("Deprecated flag parsing", func() {
Expect(arg.ManifestPath).To(Equal("../fixtures/manifest.yml"))
Expect(arg.VenerableAction).Should(Equal("stop"))
})

It("manifest path with wildcard in path test", func() {
_, err := ParseArgs(
[]string{
"zero-downtime-push",
"appname",
"-f", "../fixtures/manifestWildcard.yml",
},
)
Expect(err).To(MatchError(ErrNoWildcardSupport))
})

It("manifest path without wildcard in path test", func() {
arg, err := ParseArgs(
[]string{
"zero-downtime-push",
"appname",
"-f", "../fixtures/manifest.yml",
},
)
Expect(err).ToNot(HaveOccurred())
Expect(arg.Manifest.ApplicationManifests[0].Path).To(Equal(""))
})
})
1 change: 1 addition & 0 deletions cf/v2/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (resource *ResourcesData) GetAppMetadata(appName string) (*AppResourcesEnti
}

if len(metaDataResponseEntity.AppResourcesEntity) == 0 {
ui.Warn("No venerable application found")
return nil, ErrAppNotFound
}

Expand Down
9 changes: 1 addition & 8 deletions cf/v3/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ var _ = Describe("cf-app test", func() {
err := resourcesData.PushApp(arguments)

Expect(fakeExecutor.ExecutorCallCount()).To(Equal(3)) //called for each env
output := fakeExecutor.ExecutorArgumentsOutput()
argumentsOutput := []string{"v3-push", "myTestApp", "--no-start"}
Expect(output[0]).To(Equal(argumentsOutput))
argumentsOutput = []string{"v3-set-env", "myTestApp", "key", "value"}
Expect(output[1]).To(Equal(argumentsOutput))
argumentsOutput = []string{"v3-set-env", "myTestApp", "newKey", "newValue"}
Expect(output[2]).To(Equal(argumentsOutput))
Expect(err).ToNot(HaveOccurred())
})

Expand All @@ -119,7 +112,7 @@ var _ = Describe("cf-app test", func() {
"--docker-image",
"myDockerImage",
"--docker-username",
"mySecretDockerUser",}
"mySecretDockerUser"}
Expect(fakeExecutor.ExecutorCallCount()).To(Equal(1))
Expect(fakeExecutor.ExecutorArgumentsOutput()[0]).To(Equal(argumentsOutput))
Expect(err).ToNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion cf/v3/push_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (resource *ResourcesData) GenerateNoRouteYml(appName string, originalManife
return manifestPathTemp, nil
}

//SwitchRoutes add new routes and switch "old" one from vendor app to the one
//SwitchRoutes add new routes and switch "old" one from venerable app to the one
func (resource *ResourcesData) SwitchRoutes(venAppName string, appName string, routes []map[string]string) (err error) {
domains, err := resource.GetDomain(routes)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions fixtures/manifestWildcard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
applications:
- name: myApp
memory: 128M
buildpacks:
- java_buildpack
instances: 1
routes:
- route: route1.external.test.com
path: myfolder/file-*.zip
1 change: 1 addition & 0 deletions manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Application struct {
Env map[string]string `yaml:"env,omitempty"`
Services []string `yaml:"services,omitempty"`
Stack string `yaml:"stack,omitempty"`
Path string `yaml:"path,omitempty"`
Timeout int `yaml:"timeout,omitempty"`
HealthCheckType string `yaml:"health-check-type,omitempty"`
HealthCheckHTTPEndpoint string `yaml:"health-check-http-endpoint,omitempty"`
Expand Down

0 comments on commit a943548

Please sign in to comment.