github.com/opensuse/umoci@v0.4.2/test/gc.bats (about) 1 #!/usr/bin/env bats -t 2 # umoci: Umoci Modifies Open Containers' Images 3 # Copyright (C) 2016, 2017, 2018 SUSE LLC. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 load helpers 18 19 function setup() { 20 setup_image 21 } 22 23 function teardown() { 24 teardown_tmpdirs 25 teardown_image 26 } 27 28 @test "umoci gc [missing args]" { 29 umoci gc 30 [ "$status" -ne 0 ] 31 } 32 33 @test "umoci gc [consistent]" { 34 # Initial gc. 35 umoci gc --layout "${IMAGE}" 36 [ "$status" -eq 0 ] 37 image-verify "${IMAGE}" 38 39 # Check how many blobs there were. 40 sane_run find "$IMAGE/blobs" -type f 41 [ "$status" -eq 0 ] 42 nblobs="${#lines[@]}" 43 44 # Redo the gc. 45 umoci gc --layout "${IMAGE}" 46 [ "$status" -eq 0 ] 47 image-verify "${IMAGE}" 48 49 # Make sure that another gc run does nothing. 50 sane_run find "$IMAGE/blobs" -type f 51 [ "$status" -eq 0 ] 52 [ "${#lines[@]}" -eq "$nblobs" ] 53 54 image-verify "${IMAGE}" 55 } 56 57 @test "umoci gc" { 58 # Initial gc. 59 umoci gc --layout "${IMAGE}" 60 [ "$status" -eq 0 ] 61 image-verify "${IMAGE}" 62 63 # Check how many blobs there were. 64 sane_run find "$IMAGE/blobs" -type f 65 [ "$status" -eq 0 ] 66 nblobs="${#lines[@]}" 67 68 # Unpack the image. 69 new_bundle_rootfs 70 umoci unpack --image "${IMAGE}:${TAG}" "$BUNDLE" 71 [ "$status" -eq 0 ] 72 bundle-verify "$BUNDLE" 73 74 # Change the rootfs. We need to chmod because of fedora. 75 chmod +w "$ROOTFS/usr/bin/." && rm -rf "$ROOTFS/usr/bin" 76 chmod +w "$ROOTFS/etc/." && rm -rf "$ROOTFS/etc" 77 78 # Repack the image under a new tag. 79 umoci repack --image "${IMAGE}:${TAG}-new" "$BUNDLE" 80 [ "$status" -eq 0 ] 81 image-verify "${IMAGE}" 82 83 # Make sure the number of blobs has changed. 84 sane_run find "$IMAGE/blobs" -type f 85 [ "$status" -eq 0 ] 86 [ "$nblobs" -ne "${#lines[@]}" ] 87 nblobs="${#lines[@]}" 88 89 # Make sure it is the same after doing a gc, because we used a new tag. 90 umoci gc --layout "${IMAGE}" 91 [ "$status" -eq 0 ] 92 image-verify "${IMAGE}" 93 94 # Make sure that another gc run does nothing. 95 sane_run find "$IMAGE/blobs" -type f 96 [ "$status" -eq 0 ] 97 [ "${#lines[@]}" -eq "$nblobs" ] 98 99 # Delete the old reference. 100 umoci rm --image "${IMAGE}:${TAG}" 101 [ "$status" -eq 0 ] 102 image-verify "${IMAGE}" 103 104 # Now do a gc which should delete some blobs. 105 umoci gc --layout "${IMAGE}" 106 [ "$status" -eq 0 ] 107 image-verify "${IMAGE}" 108 109 # Make sure that another gc run does nothing. 110 sane_run find "$IMAGE/blobs" -type f 111 [ "$status" -eq 0 ] 112 [ "${#lines[@]}" -lt "$nblobs" ] 113 114 image-verify "${IMAGE}" 115 } 116 117 @test "umoci gc [empty]" { 118 # Initial gc. 119 umoci gc --layout "${IMAGE}" 120 [ "$status" -eq 0 ] 121 image-verify "${IMAGE}" 122 123 # Check how many blobs there were. 124 sane_run find "$IMAGE/blobs" -type f 125 [ "$status" -eq 0 ] 126 [ "${#lines[@]}" -ne 0 ] 127 128 # Remove refs. 129 umoci ls --layout "${IMAGE}" 130 [ "$status" -eq 0 ] 131 [ "${#lines[@]}" -gt 0 ] 132 image-verify "${IMAGE}" 133 134 for line in "${lines[*]}"; do 135 umoci rm --image "${IMAGE}:${line}" 136 [ "$status" -eq 0 ] 137 image-verify "${IMAGE}" 138 done 139 140 # Do a gc, which should remove all blobs. 141 umoci gc --layout "${IMAGE}" 142 [ "$status" -eq 0 ] 143 image-verify "${IMAGE}" 144 145 # Check how many blobs there were. 146 sane_run find "$IMAGE/blobs" -type f 147 [ "$status" -eq 0 ] 148 [ "${#lines[@]}" -eq 0 ] 149 150 image-verify "${IMAGE}" 151 } 152 153 @test "umoci gc [internal]" { 154 # Initial gc. 155 umoci gc --layout "${IMAGE}" 156 [ "$status" -eq 0 ] 157 image-verify "${IMAGE}" 158 159 # Create unused directories. 160 touch "${IMAGE}/.internal" 161 touch "${IMAGE}/ magical file " 162 mkdir "${IMAGE}/ __ internal __ directory" 163 touch "${IMAGE}/ __ internal __ directory/.abc" 164 165 # Do a gc, which should remove the temporary files/directories. 166 umoci gc --layout "${IMAGE}" 167 [ "$status" -eq 0 ] 168 image-verify "${IMAGE}" 169 170 # Make sure it's gone. 171 ! [ -e "${IMAGE}/.internal" ] 172 ! [ -e "${IMAGE}/ magical file " ] 173 ! [ -e "${IMAGE}/ __ internal __ directory" ] 174 ! [ -e "${IMAGE}/ __ internal __ directory/.abc" ] 175 176 image-verify "${IMAGE}" 177 }