Skip to content

Commit

Permalink
fix: reject --image when multiple score files are provided
Browse files Browse the repository at this point in the history
  • Loading branch information
astromechza committed Sep 5, 2024
1 parent 26e2211 commit 5800ce1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions main_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ manifests. All resources and links between Workloads will be resolved and provis
}
state := &sd.State

if len(args) != 1 && (cmd.Flags().Lookup(generateCmdOverridesFileFlag).Changed || cmd.Flags().Lookup(generateCmdOverridePropertyFlag).Changed) {
return errors.Errorf("cannot use --%s or --%s when 0 or more than 1 score files are provided", generateCmdOverridePropertyFlag, generateCmdOverridesFileFlag)
if len(args) != 1 && (cmd.Flags().Lookup(generateCmdOverridesFileFlag).Changed || cmd.Flags().Lookup(generateCmdOverridePropertyFlag).Changed || cmd.Flags().Lookup(generateCmdImageFlag).Changed) {
return errors.Errorf("cannot use --%s, --%s, or --%s when 0 or more than 1 score files are provided", generateCmdOverridePropertyFlag, generateCmdOverridesFileFlag, generateCmdImageFlag)
}

slices.Sort(args)
Expand Down
28 changes: 28 additions & 0 deletions main_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,31 @@ resources:

assert.Contains(t, string(raw), string(raw2))
}

func TestGenerateMultipleSpecsWithImage(t *testing.T) {
td := changeToTempDir(t)
stdout, _, err := executeAndResetCommand(context.Background(), rootCmd, []string{"init"})
assert.NoError(t, err)
assert.Equal(t, "", stdout)
assert.NoError(t, os.WriteFile(filepath.Join(td, "scoreA.yaml"), []byte(`
apiVersion: score.dev/v1b1
metadata:
name: example-a
containers:
hello:
image: foo
`), 0644))
assert.NoError(t, os.WriteFile(filepath.Join(td, "scoreB.yaml"), []byte(`
apiVersion: score.dev/v1b1
metadata:
name: example-b
containers:
hello:
image: foo
`), 0644))
stdout, _, err = executeAndResetCommand(context.Background(), rootCmd, []string{
"generate", "--image", "nginx:latest", "scoreA.yaml", "scoreB.yaml",
})
assert.EqualError(t, err, "cannot use --override-property, --overrides-file, or --image when 0 or more than 1 score files are provided")
assert.Equal(t, "", stdout)
}

0 comments on commit 5800ce1

Please sign in to comment.