|
| 1 | +load helpers |
| 2 | +load helpers.network |
| 3 | +load helpers.registry |
| 4 | + |
| 5 | +@test "podman pull with policy flag" { |
| 6 | + skip_if_remote "tests depend on start_registry which does not work with podman-remote" |
| 7 | + start_registry |
| 8 | + |
| 9 | + local registry=localhost:${PODMAN_LOGIN_REGISTRY_PORT} |
| 10 | + local image_for_test=$registry/i-$(safename):$(random_string) |
| 11 | + local authfile=$PODMAN_TMPDIR/authfile.json |
| 12 | + |
| 13 | + run_podman login --authfile=$authfile \ |
| 14 | + --tls-verify=false \ |
| 15 | + --username ${PODMAN_LOGIN_USER} \ |
| 16 | + --password ${PODMAN_LOGIN_PASS} \ |
| 17 | + $registry |
| 18 | + |
| 19 | + # Generate a test image and push it to the registry. |
| 20 | + # For safety in parallel runs, test image must be isolated |
| 21 | + # from $IMAGE. A simple add-tag will not work. (#23756) |
| 22 | + run_podman create -q $IMAGE true |
| 23 | + local tmpcid=$output |
| 24 | + run_podman commit -q $tmpcid $image_for_test |
| 25 | + local image_id=$output |
| 26 | + run_podman rm $tmpcid |
| 27 | + run_podman image push --tls-verify=false --authfile=$authfile $image_for_test |
| 28 | + # Remove the local image to make sure it will be pulled again |
| 29 | + run_podman image rm --ignore $image_for_test |
| 30 | + |
| 31 | + # Test invalid policy |
| 32 | + run_podman 125 pull --tls-verify=false --authfile $authfile --policy invalid $image_for_test |
| 33 | + assert "$output" = "Error: unsupported pull policy \"invalid\"" |
| 34 | + |
| 35 | + # Test policy=never with image not present |
| 36 | + run_podman 125 pull --tls-verify=false --authfile $authfile --policy never $image_for_test |
| 37 | + assert "$output" = "Error: $image_for_test: image not known" |
| 38 | + |
| 39 | + # Test policy=missing with image not present (should succeed) |
| 40 | + run_podman pull --tls-verify=false --authfile $authfile --policy missing $image_for_test |
| 41 | + assert "$output" =~ "Writing manifest to image destination" |
| 42 | + |
| 43 | + # Test policy=missing with image present (should not pull again) |
| 44 | + run_podman pull --tls-verify=false --authfile $authfile --policy missing $image_for_test |
| 45 | + assert "$output" = $image_id |
| 46 | + |
| 47 | + # Test policy=always (should always pull) |
| 48 | + run_podman pull --tls-verify=false --authfile $authfile --policy always $image_for_test |
| 49 | + assert "$output" =~ "Writing manifest to image destination" |
| 50 | + |
| 51 | + # Test policy=newer with image present and no new image(should not pull again) |
| 52 | + run_podman pull --tls-verify=false --authfile $authfile --policy newer $image_for_test |
| 53 | + assert "$output" = $image_id |
| 54 | + |
| 55 | + run_podman image rm --ignore $image_for_test |
| 56 | +} |
| 57 | + |
| 58 | +@test "podman pull with policy flag - remote" { |
| 59 | + # Make sure image is not pulled when policy is never |
| 60 | + run_podman 125 pull --policy never quay.io/libpod/i-do-not-exist |
| 61 | + assert "$output" = "Error: quay.io/libpod/i-do-not-exist: image not known" |
| 62 | +} |
0 commit comments