File: formats.bats

package info (click to toggle)
golang-github-containers-buildah 1.39.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,724 kB
  • sloc: sh: 2,398; makefile: 236; perl: 187; asm: 16; awk: 12; ansic: 1
file content (70 lines) | stat: -rw-r--r-- 2,578 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bats

load helpers

###################
#  check_imgtype  #  shortcut for running 'imgtype' and verifying image
###################
function check_imgtype() {
  # First argument: image name
  image="$1"

  # Second argument: expected image type, 'oci' or 'docker'
  imgtype_oci="application/vnd.oci.image.manifest.v1+json"
  imgtype_dkr="application/vnd.docker.distribution.manifest.v2+json"

  expect=""
  case "$2" in
      oci)    want=$imgtype_oci; reject=$imgtype_dkr;;
      docker) want=$imgtype_dkr; reject=$imgtype_oci;;
      *)      die "Internal error: unknown image type '$2'";;
  esac

  # First test: run imgtype with expected type, confirm exit 0 + no output
  echo "\$ imgtype -expected-manifest-type $want $image"
  run imgtype -expected-manifest-type $want $image
  echo "$output"
  if [[ $status -ne 0 ]]; then
    die "exit status is $status (expected 0)"
  fi
  expect_output "" "Checking imagetype($image) == $2"

  # Second test: the converse. Run imgtype with the WRONG expected type,
  # confirm error message and exit status 1
  echo "\$ imgtype -expected-manifest-type $reject $image [opposite test]"
  run imgtype -expected-manifest-type $reject $image
  echo "$output"
  if [[ $status -ne 1 ]]; then
    die "exit status is $status (expected 1)"
  fi

  # Can't embed entire string because the '+' sign is interpreted as regex
  expect_output --substring \
                "level=error msg=\"expected .* type \\\\\".*, got " \
                "Checking imagetype($image) == $2"
}


@test "write-formats" {
  skip_if_rootless_environment
  run_buildah from --pull=false $WITH_POLICY_JSON scratch
  cid=$output
  run_buildah commit $WITH_POLICY_JSON $cid scratch-image-default
  run_buildah commit --format docker $WITH_POLICY_JSON $cid scratch-image-docker
  run_buildah commit --format oci $WITH_POLICY_JSON $cid scratch-image-oci

  check_imgtype scratch-image-default oci
  check_imgtype scratch-image-oci     oci
  check_imgtype scratch-image-docker  docker
}

@test "bud-formats" {
  skip_if_rootless_environment
  run_buildah build-using-dockerfile $WITH_POLICY_JSON -t scratch-image-default -f Containerfile $BUDFILES/from-scratch
  run_buildah build-using-dockerfile --format docker $WITH_POLICY_JSON -t scratch-image-docker -f Containerfile $BUDFILES/from-scratch
  run_buildah build-using-dockerfile --format oci $WITH_POLICY_JSON -t scratch-image-oci -f Containerfile $BUDFILES/from-scratch

  check_imgtype scratch-image-default oci
  check_imgtype scratch-image-oci     oci
  check_imgtype scratch-image-docker  docker
}