github.com/containers/podman/v5@v5.1.0-rc1/test/system/110-history.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load helpers
     4  
     5  @test "podman history - basic tests" {
     6      tests="
     7                                   | .*[0-9a-f]\\\{12\\\} .* CMD .* LABEL
     8  --format '{{.ID}} {{.Created}}'  | .*[0-9a-f]\\\{12\\\} .* ago
     9  --human=false                    | .*[0-9a-f]\\\{12\\\} *[0-9-]\\\+T[0-9:]\\\+Z
    10  -qH                              | .*[0-9a-f]\\\{12\\\}
    11  --no-trunc                       | .*[0-9a-f]\\\{64\\\}
    12  "
    13  
    14      defer-assertion-failures
    15  
    16      while read options expect; do
    17          if [ "$options" = "''" ]; then options=; fi
    18  
    19          eval set -- "$options"
    20  
    21          run_podman history "$@" $IMAGE
    22          is "$output" "$expect" "podman history $options"
    23      done < <(parse_table "$tests")
    24  }
    25  
    26  @test "podman history - custom format" {
    27      run_podman history --format "{{.ID}}\t{{.ID}}" $IMAGE
    28      od -c <<<$output
    29      while IFS= read -r row; do
    30          is "$row" ".*	.*$"
    31      done <<<$output
    32  
    33      run_podman history --format "{{.Tags}}" $IMAGE
    34      is "$output" "\[$IMAGE\].*" "podman history sets tags"
    35  }
    36  
    37  @test "podman history - json" {
    38      # Sigh. Timestamp in .created can be '...Z' or '...-06:00'
    39      tests="
    40  id        | [0-9a-f]\\\{64\\\}
    41  created   | [0-9-]\\\+T[0-9:.]\\\+[Z0-9:+-]\\\+
    42  size      | -\\\?[0-9]\\\+
    43  "
    44  
    45      run_podman history --format json $IMAGE
    46  
    47      defer-assertion-failures
    48  
    49      while read field expect; do
    50          # HACK: we can't include '|' in the table
    51          if [ "$field" = "id" ]; then expect="$expect\|<missing>";fi
    52  
    53          # output is an array of dicts; check each one
    54          count=$(echo "$output" | jq '. | length')
    55          i=0
    56          while [ $i -lt $count ]; do
    57              actual=$(echo "$output" | jq -r ".[$i].$field")
    58              is "$actual" "$expect\$" "jq .[$i].$field"
    59              i=$(expr $i + 1)
    60          done
    61      done < <(parse_table "$tests")
    62  }
    63  
    64  @test "podman image history Created" {
    65      # Values from image LIST
    66      run_podman image list --format '{{.CreatedSince}}\n{{.CreatedAt}}' $IMAGE
    67      imagelist_since="${lines[0]}"
    68      imagelist_at="${lines[1]}"
    69  
    70      assert "${imagelist_since}" =~ "^[0-9]+.* ago" \
    71             "image list: CreatedSince looks reasonable"
    72      assert "${imagelist_at}" =~ "^[0-9]+-[0-9]+-[0-9]+ [0-9:]+ \+0000 UTC\$" \
    73             "image list: CreatedAt looks reasonable"
    74  
    75      # Values from image HISTORY. For docker compatibility, this command now
    76      # honors $TZ (#18213) for CreatedAt.
    77      TZ=UTC run_podman image history --format '{{.CreatedSince}}\n{{.CreatedAt}}' $IMAGE
    78      imagehistory_since="${lines[0]}"
    79      imagehistory_at="${lines[1]}"
    80  
    81      assert "$imagehistory_since" == "$imagelist_since" \
    82             "CreatedSince from image history should == image list"
    83  
    84      # More docker compatibility: both commands emit ISO8601-ish dates but
    85      # with different separators so we need to compare date & time separately.
    86      assert "${imagehistory_at:0:10}" == "${imagelist_at:0:10}" \
    87             "CreatedAt (date) from image history should == image list"
    88      assert "${imagehistory_at:11:8}" == "${imagelist_at:11:8}" \
    89             "CreatedAt (time) from image history should == image list"
    90  }
    91  
    92  # vim: filetype=sh