zotregistry.dev/zot@v1.4.4-0.20240314164342-eec277e14d20/test/blackbox/delete_images.bats (about)

     1  # Note: Intended to be run as "make run-blackbox-tests" or "make run-blackbox-ci"
     2  #       Makefile target installs & checks all necessary tooling
     3  #       Extra tools that are not covered in Makefile target needs to be added in verify_prerequisites()
     4  
     5  load helpers_zot
     6  
     7  function verify_prerequisites {
     8      if [ ! command -v curl ] &>/dev/null; then
     9          echo "you need to install curl as a prerequisite to running the tests" >&3
    10          return 1
    11      fi
    12  
    13      if [ ! command -v jq ] &>/dev/null; then
    14          echo "you need to install jq as a prerequisite to running the tests" >&3
    15          return 1
    16      fi
    17  }
    18  
    19  function setup_file() {
    20      # Verify prerequisites are available
    21      if ! verify_prerequisites; then
    22          exit 1
    23      fi
    24  
    25      # Download test data to folder common for the entire suite, not just this file
    26      skopeo --insecure-policy copy --format=oci docker://ghcr.io/project-zot/test-images/alpine:3.17.3 oci:${TEST_DATA_DIR}/alpine:3.17.3
    27  
    28      # Setup zot server
    29      ZOT_ROOT_DIR=${BATS_FILE_TMPDIR}/zot
    30      echo ${ZOT_ROOT_DIR}
    31      local zot_log_file=${BATS_FILE_TMPDIR}/zot-log.json
    32      local zot_config_file=${BATS_FILE_TMPDIR}/zot_config.json
    33      mkdir -p ${ZOT_ROOT_DIR}
    34      touch ${zot_log_file}
    35      zot_port=$(get_free_port)
    36      echo ${zot_port} > ${BATS_FILE_TMPDIR}/zot.port
    37      cat >${zot_config_file} <<EOF
    38  {
    39      "distSpecVersion": "1.1.0",
    40      "storage": {
    41          "rootDirectory": "${ZOT_ROOT_DIR}"
    42      },
    43      "http": {
    44          "address": "0.0.0.0",
    45          "port": "${zot_port}"
    46      },
    47      "log": {
    48          "level": "debug",
    49          "output": "${zot_log_file}"
    50      },
    51      "extensions": {
    52          "search": {
    53              "enable": true
    54          }
    55      }
    56  }
    57  EOF
    58  
    59      zot_serve ${ZOT_PATH} ${zot_config_file}
    60      wait_zot_reachable ${zot_port}
    61  
    62      run skopeo --insecure-policy copy --dest-tls-verify=false \
    63          oci:${TEST_DATA_DIR}/alpine:3.17.3 \
    64          docker://127.0.0.1:${zot_port}/alpine:3.17.3
    65      [ "$status" -eq 0 ]
    66      run curl http://127.0.0.1:${zot_port}/v2/_catalog
    67      [ "$status" -eq 0 ]
    68      [ $(echo "${lines[-1]}" | jq '.repositories[]') = '"alpine"' ]
    69  
    70      MANIFEST_DIGEST=$(skopeo inspect --tls-verify=false docker://localhost:${zot_port}/alpine:3.17.3 | jq -r '.Digest')
    71      echo ${MANIFEST_DIGEST}
    72  }
    73  
    74  function teardown() {
    75      # conditionally printing on failure is possible from teardown but not from from teardown_file
    76      cat ${BATS_FILE_TMPDIR}/zot-log.json
    77  }
    78  
    79  function teardown_file() {
    80      zot_stop_all
    81  }
    82  
    83  @test "delete one manifest by it's tag" {
    84      zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
    85      run curl http://127.0.0.1:${zot_port}/v2/_catalog
    86      [ "$status" -eq 0 ]
    87      [ $(echo "${lines[-1]}" | jq '.repositories[]') = '"alpine"' ]
    88  
    89      run curl -i -X GET  http://localhost:${zot_port}/v2/alpine/manifests/3.17.3
    90      [ "$status" -eq 0 ]
    91      echo $(echo "${lines[-1]}")
    92  
    93      foundConfigDigest=0
    94      for i in "${lines[@]}"
    95      do
    96          if [[ "$i" == *"\"digest\":\"sha256:4798f93a2cc876a25ef1f5ae73e7a2ff7132ddc2746fc22632a2641b318eb56c\""* ]]; then
    97              foundConfigDigest=1
    98          fi
    99      done
   100      [ "$foundConfigDigest" -eq 1 ]
   101  
   102      run curl -X DELETE  http://localhost:${zot_port}/v2/alpine/manifests/3.17.3
   103      [ "$status" -eq 0 ]
   104  
   105      run curl -i -X GET  http://localhost:${zot_port}/v2/alpine/manifests/3.17.3
   106      [ "$status" -eq 0 ]
   107      
   108      found=0
   109      for i in "${lines[@]}"
   110      do
   111          if [[ "$i" = *"MANIFEST_UNKNOWN"* ]]; then
   112              found=1
   113          fi
   114      done
   115      [ "$found" -eq 1 ]
   116  }