Skip to content

Commit

Permalink
cmd/list: Support images without names
Browse files Browse the repository at this point in the history
Some people create images manually. If such created images are recognize
as toolbox images (they have the proper labels) but do not have
a name/tag then 'toolbox list' will panic due to index being out of
range.

#800
  • Loading branch information
HarryMichal committed Jun 22, 2021
1 parent eaefb3d commit c6c2e42
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,14 @@ func listOutput(images []toolboxImage, containers []toolboxContainer) {
fmt.Fprintf(writer, "%s\t%s\t%s\n", "IMAGE ID", "IMAGE NAME", "CREATED")

for _, image := range images {
imageName := "<none>"
if len(image.Names) != 0 {
imageName = image.Names[0]
}

fmt.Fprintf(writer, "%s\t%s\t%s\n",
utils.ShortID(image.ID),
image.Names[0],
imageName,
image.Created)
}

Expand Down
19 changes: 19 additions & 0 deletions test/system/102-list.bats
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,22 @@ teardown() {
assert_output --partial "non-default-one"
assert_output --partial "non-default-two"
}

@test "list: List an image without a name" {
echo -e "FROM scratch\n\nLABEL com.github.containers.toolbox=\"true\"" > "$BATS_TMPDIR"/Containerfile

run $PODMAN build "$BATS_TMPDIR"

assert_success
assert_line --index 0 "STEP 1: FROM scratch"
assert_line --index 1 "STEP 2: LABEL com.github.containers.toolbox=\"true\""
assert_line --index 2 "STEP 3: COMMIT"
assert_line --index 3 --regexp "^--> [a-z0-9]*$"

run $TOOLBOX list

assert_success
assert_line --index 1 --partial "<none>"

rm -f "$BATS_TMPDIR"/Containerfile
}

0 comments on commit c6c2e42

Please sign in to comment.