Skip to content

Commit

Permalink
Updated system test to be easier to read
Browse files Browse the repository at this point in the history
Following @edsantiago guidance,

* Additional explanations for each step of the test
* Timezone for tests normalized to UTC
* Smarter choice of separator and use of shell substring extraction

Signed-off-by: rbagd <[email protected]>
  • Loading branch information
rbagd committed Apr 19, 2023
1 parent 6e0cf93 commit bce38c1
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions test/system/110-history.bats
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +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"

# Values from image HISTORY
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" \
run_podman image list --format '{{.CreatedSince}}\n{{.CreatedAt}}' $IMAGE
imagelist_since="${lines[0]}"
imagelist_at="${lines[1]}"

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"

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"
# 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

0 comments on commit bce38c1

Please sign in to comment.