mirror of
https://github.com/containers/podman.git
synced 2026-10-22 01:45:09 -04:00
Merge pull request #18213 from rbagd/main
Fixes format inconsistencies with docker for certain history fields
This commit is contained in:
3 files changed
+30
-14
No files matched your search
@@ -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"
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -57,15 +57,30 @@ size | -\\\?[0-9]\\\+
|
||||
|
||||
@test "podman image history Created" {
|
||||
# Values from image LIST
|
||||
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:]+ " \
|
||||
"CreatedSince and CreatedAt look reasonable"
|
||||
run_podman image list --format '{{.CreatedSince}}\n{{.CreatedAt}}' $IMAGE
|
||||
imagelist_since="${lines[0]}"
|
||||
imagelist_at="${lines[1]}"
|
||||
|
||||
# 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"
|
||||
assert "${imagelist_since}" =~ "^[0-9]+.* ago" \
|
||||
"image list: CreatedSince looks reasonable"
|
||||
assert "${imagelist_at}" =~ "^[0-9]+-[0-9]+-[0-9]+ [0-9:]+ \+0000 UTC\$" \
|
||||
"image list: CreatedAt looks reasonable"
|
||||
|
||||
# Values from image HISTORY. For docker compatibility, this command now
|
||||
# honors $TZ (#18213) for CreatedAt.
|
||||
TZ=UTC run_podman image history --format '{{.CreatedSince}}\n{{.CreatedAt}}' $IMAGE
|
||||
imagehistory_since="${lines[0]}"
|
||||
imagehistory_at="${lines[1]}"
|
||||
|
||||
assert "$imagehistory_since" == "$imagelist_since" \
|
||||
"CreatedSince from image history should == image list"
|
||||
|
||||
# More docker compatibility: both commands emit ISO8601-ish dates but
|
||||
# with different separators so we need to compare date & time separately.
|
||||
assert "${imagehistory_at:0:10}" == "${imagelist_at:0:10}" \
|
||||
"CreatedAt (date) from image history should == image list"
|
||||
assert "${imagehistory_at:11:8}" == "${imagelist_at:11:8}" \
|
||||
"CreatedAt (time) from image history should == image list"
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
Reference in new issue
Block a user