Skip to content

Commit

Permalink
manifest add --artifact: handle multiple values
Browse files Browse the repository at this point in the history
Don't error out when `manifest add --artifact` is given multiple files,
and add a test which should have checked that.

Signed-off-by: Nalin Dahyabhai <[email protected]>
  • Loading branch information
nalind committed Sep 11, 2024
1 parent 19e7088 commit edc43c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 6 additions & 9 deletions cmd/buildah/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,25 +432,22 @@ func manifestAddCmd(c *cobra.Command, args []string, opts manifestAddOpts) error
switch len(args) {
case 0, 1:
return errors.New("At least a list image and an image or artifact to add must be specified")
case 2:
default:
listImageSpec = args[0]
if listImageSpec == "" {
return fmt.Errorf(`Invalid image name "%s"`, args[0])
return fmt.Errorf("Invalid image name %q", args[0])
}
if opts.artifact {
artifactSpec = args[1:]
} else {
if len(args) > 2 {
return errors.New("Too many arguments: expected list and image add to list")
}
imageSpec = args[1]
if imageSpec == "" {
return fmt.Errorf(`Invalid image name "%s"`, args[1])
return fmt.Errorf("Invalid image name %q", args[1])
}
}
default:
if opts.artifact {
artifactSpec = args[1:]
} else {
return errors.New("Too many arguments: expected list and image add to list")
}
}

store, err := getStore(c)
Expand Down
8 changes: 8 additions & 0 deletions tests/lists.bats
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ IMAGE_LIST_S390X_INSTANCE_DIGEST=sha256:882a20ee0df7399a445285361d38b711c299ca09
run_buildah manifest rm foo
}

@test "manifest-add-multiple-artifacts" {
run_buildah manifest create foo
createrandom $TEST_SCRATCH_DIR/randomfile4
createrandom $TEST_SCRATCH_DIR/randomfile3
run_buildah manifest add --artifact foo $TEST_SCRATCH_DIR/randomfile3 $TEST_SCRATCH_DIR/randomfile4
run_buildah manifest push --all foo oci:$TEST_SCRATCH_DIR/pushed
}

@test "manifest-add local image" {
target=scratch-image
run_buildah bud $WITH_POLICY_JSON -t ${target} $BUDFILES/from-scratch
Expand Down

0 comments on commit edc43c4

Please sign in to comment.