fix: app create with -f should not ignore other options (#4322)

This commit is contained in:
May Zhang 2020-09-14 15:29:45 -07:00 committed by GitHub
parent 4e6d8cc1d2
commit cfb925c0d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 3 deletions

View file

@ -153,8 +153,15 @@ func NewApplicationCreateCommand(clientOpts *argocdclient.ClientOptions) *cobra.
log.Fatalf("app name '%s' does not match app spec metadata.name '%s'", args[0], app.Name)
}
if appName != "" && appName != app.Name {
log.Fatalf("--name argument '%s' does not match app spec metadata.name '%s'", appName, app.Name)
app.Name = appName
}
if app.Name == "" {
log.Fatalf("app.Name is empty. --name argument can be used to provide app.Name")
}
setAppSpecOptions(c.Flags(), &app.Spec, &appOpts)
setParameterOverrides(&app, appOpts.parameters)
setLabels(&app, labels)
} else {
// read arguments
if len(args) == 1 {

View file

@ -1381,3 +1381,24 @@ func TestCreateDisableValidation(t *testing.T) {
AppSet("--path", "baddir3", "--validate=false")
}
func TestCreateFromPartialFile(t *testing.T) {
partialApp :=
`spec:
syncPolicy:
automated: {prune: true }`
path := "helm-values"
Given(t).
When().
// app should be auto-synced once created
CreateFromPartialFile(partialApp, "--path", path, "--helm-set", "foo=foo").
Then().
Expect(Success("")).
Expect(SyncStatusIs(SyncStatusCodeSynced)).
Expect(NoConditions()).
And(func(app *Application) {
assert.Equal(t, path, app.Spec.Source.Path)
assert.Equal(t, []HelmParameter{{Name: "foo", Value: "foo"}}, app.Spec.Source.Helm.Parameters)
})
}

View file

@ -58,7 +58,26 @@ func (a *Actions) AddSignedFile(fileName, fileContents string) *Actions {
return a
}
func (a *Actions) CreateFromFile(handler func(app *Application)) *Actions {
func (a *Actions) CreateFromPartialFile(data string, flags ...string) *Actions {
a.context.t.Helper()
tmpFile, err := ioutil.TempFile("", "")
errors.CheckError(err)
_, err = tmpFile.Write([]byte(data))
errors.CheckError(err)
args := append([]string{
"app", "create",
"-f", tmpFile.Name(),
"--name", a.context.name,
"--repo", fixture.RepoURL(a.context.repoURLType),
"--dest-server", a.context.destServer,
"--dest-namespace", fixture.DeploymentNamespace(),
}, flags...)
a.runCli(args...)
return a
}
func (a *Actions) CreateFromFile(handler func(app *Application), flags ...string) *Actions {
a.context.t.Helper()
app := &Application{
ObjectMeta: v1.ObjectMeta{
@ -108,7 +127,12 @@ func (a *Actions) CreateFromFile(handler func(app *Application)) *Actions {
_, err = tmpFile.Write(data)
errors.CheckError(err)
a.runCli("app", "create", "-f", tmpFile.Name())
args := append([]string{
"app", "create",
"-f", tmpFile.Name(),
}, flags...)
a.runCli(args...)
return a
}