Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes format inconsistencies with docker for certain history fields #18213

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions cmd/podman/images/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package images
import (
"fmt"
"os"
"strings"
"time"
"unicode"

"github.com/containers/common/pkg/report"
"github.com/containers/podman/v4/cmd/podman/common"
Expand Down Expand Up @@ -149,9 +147,7 @@ func (h historyReporter) Created() string {
}

func (h historyReporter) Size() string {
s := units.HumanSizeWithPrecision(float64(h.ImageHistoryLayer.Size), 3)
i := strings.LastIndexFunc(s, unicode.IsNumber)
return s[:i+1] + " " + s[i+1:]
return units.HumanSizeWithPrecision(float64(h.ImageHistoryLayer.Size), 3)
}

func (h historyReporter) CreatedBy() string {
Expand All @@ -169,7 +165,7 @@ func (h historyReporter) ID() string {
}

func (h historyReporter) CreatedAt() string {
return time.Unix(h.ImageHistoryLayer.Created.Unix(), 0).UTC().String()
return time.Unix(h.ImageHistoryLayer.Created.Unix(), 0).Format(time.RFC3339)
}

func (h historyReporter) CreatedSince() string {
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ var _ = Describe("Podman history", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.OutputToStringArray()).ToNot(BeEmpty())

session = podmanTest.Podman([]string{"history", "--format", "{{.CreatedAt}};{{.Size}}", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(MatchRegexp("[0-9-]{10}T[0-9:]{8}[Z0-9+:-]+;[0-9.]+[MG]*B( .+)?"))
})

It("podman history with human flag", func() {
Expand Down
21 changes: 16 additions & 5 deletions test/system/110-history.bats
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,26 @@ size | -\\\?[0-9]\\\+

@test "podman image history Created" {
# Values from image LIST
run_podman image list --format '{{.CreatedSince}}--{{.CreatedAt}}' $IMAGE
run_podman image list --format '{{.CreatedSince}};{{.CreatedAt}}' $IMAGE
from_imagelist="$output"
assert "$from_imagelist" =~ "^[0-9].* ago--[0-9]+-[0-9]+-[0-9]+ [0-9:]+ " \
assert "$from_imagelist" =~ "^[0-9].* ago;[0-9]+-[0-9]+-[0-9]+ [0-9:]+ " \
"CreatedSince and CreatedAt look reasonable"

# Values from image HISTORY
run_podman image history --format '{{.CreatedSince}}--{{.CreatedAt}}' $IMAGE
assert "${lines[0]}" == "$from_imagelist" \
"CreatedSince and CreatedAt from image history should == image list"
run_podman image history --format '{{.CreatedSince}};{{.CreatedAt}}' $IMAGE
from_imagehistory="${lines[0]}"

imagelist_since=$(echo "$from_imagelist" | cut -d';' -f1)
imagehist_since=$(echo "$from_imagehistory" | cut -d';' -f1)

assert "$imagehist_since" == "$imagelist_since" \
"CreatedSince from image history should == image list"

imagelist_at=$(date --rfc-3339=seconds -f <(echo "$from_imagelist" | cut -d';' -f2 | sed 's/ UTC//'))
imagehist_at=$(date --rfc-3339=seconds -f <(echo "$from_imagehistory" | cut -d';' -f2))

assert "$imagehist_at" == "$imagelist_at" \
"CreatedAt from image history should == image list"
rbagd marked this conversation as resolved.
Show resolved Hide resolved
}

# vim: filetype=sh