github.com/containers/podman/v5@v5.1.0-rc1/test/apiv2/30-volumes.at (about) 1 # -*- sh -*- 2 # 3 # volume-related tests 4 # 5 6 ## create volume 7 t GET libpod/info 200 8 volumepath=$(jq -r ".store.volumePath" <<<"$output") 9 t POST libpod/volumes/create name=foo1 201 \ 10 .Name=foo1 \ 11 .Driver=local \ 12 .Mountpoint=$volumepath/foo1/_data \ 13 .CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.* \ 14 .Labels={} \ 15 .Options={} 16 # TODO(mwhahaha): there might be a bug here since options is null and not {} 17 t POST volumes/create 201 \ 18 .Name~[0-9a-f]\\{64\\} \ 19 .Driver=local \ 20 .Mountpoint~$volumepath/[0-9a-f]\\{64\\}/_data \ 21 .CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.* \ 22 .Labels={} \ 23 .Options=null 24 t POST libpod/volumes/create 201 25 t POST libpod/volumes/create \ 26 Name=foo2 \ 27 Label='{"testlabel":"testonly"}' \ 28 Options='{"type":"tmpfs","o":"nodev,noexec"}}' \ 29 201 \ 30 .Name=foo2 \ 31 .Labels.testlabel=testonly \ 32 .Options.type=tmpfs \ 33 .Options.o=nodev,noexec 34 t POST libpod/volumes/create \ 35 Name=foo3 \ 36 Label='{"testlabel":""}' \ 37 Options='{"type":"tmpfs","o":"nodev,noexec"}}' \ 38 201 \ 39 .Name=foo3 \ 40 .Labels.testlabel="" \ 41 .Options.type=tmpfs \ 42 .Options.o=nodev,noexec 43 t POST libpod/volumes/create \ 44 Name=foo4 \ 45 Label='{"testlabel1":"testonly"}' \ 46 Options='{"type":"tmpfs","o":"nodev,noexec"}}' \ 47 201 \ 48 .Name=foo4 \ 49 .Labels.testlabel1=testonly \ 50 .Options.type=tmpfs \ 51 .Options.o=nodev,noexec 52 53 # Negative test 54 # We have created a volume named "foo1" 55 t POST libpod/volumes/create name=foo1 500 \ 56 .cause="volume already exists" \ 57 .message~.* \ 58 .response=500 59 60 ## list volume 61 t GET libpod/volumes/json 200 \ 62 .[0].Name~.* \ 63 .[0].Mountpoint~.* \ 64 .[0].CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.* 65 t GET libpod/volumes/json?filters='{"name":["foo1"]}' 200 \ 66 length=1 \ 67 .[0].Name=foo1 68 t GET libpod/volumes/json?filters='{"name":%20["foo1",%20"foo2"]}' 200 \ 69 length=2 \ 70 .[0].Name=foo1 \ 71 .[1].Name=foo2 72 t GET libpod/volumes/json?filters='{"name":["nonexistent"]}' 200 length=0 73 t GET libpod/volumes/json?filters='{"label":["testlabel"]}' 200 length=2 74 t GET libpod/volumes/json?filters='{"label":["testlabel=testonly"]}' 200 length=1 75 t GET libpod/volumes/json?filters='{"label":["testlabel1=testonly"]}' 200 length=1 76 77 ## inspect volume 78 t GET libpod/volumes/foo1/json 200 \ 79 .Name=foo1 \ 80 .Mountpoint=$volumepath/foo1/_data \ 81 .CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.* 82 t GET libpod/volumes/nonexistent/json 404 \ 83 .cause="no such volume" \ 84 .message~.* \ 85 .response=404 86 87 ## Remove volumes 88 t DELETE libpod/volumes/foo1 204 89 #After remove foo1 volume, this volume should not exist 90 t GET libpod/volumes/foo1/json 404 91 # Negative test 92 t DELETE libpod/volumes/foo1 404 \ 93 .cause="no such volume" \ 94 .message~.* \ 95 .response=404 96 97 #compat api list volumes sanity checks 98 t GET volumes?filters='garb1age}' 500 \ 99 .cause="invalid character 'g' looking for beginning of value" 100 t GET volumes?filters='{"label":["testl' 500 \ 101 .cause="unexpected end of JSON input" 102 103 #libpod api list volumes sanity checks 104 t GET libpod/volumes/json?filters='garb1age}' 500 \ 105 .cause="invalid character 'g' looking for beginning of value" 106 t GET libpod/volumes/json?filters='{"label":["testl' 500 \ 107 .cause="unexpected end of JSON input" 108 109 # Prune volumes - bad filter input 110 t POST volumes/prune?filters='garb1age}' 500 \ 111 .cause="invalid character 'g' looking for beginning of value" 112 t POST libpod/volumes/prune?filters='garb1age}' 500 \ 113 .cause="invalid character 'g' looking for beginning of value" 114 115 ## Prune volumes with label matching 'testlabel1=testonly' 116 t POST libpod/volumes/prune?filters='{"label":["testlabel1=testonly"]}' 200 117 t GET libpod/volumes/json?filters='{"label":["testlabel1=testonly"]}' 200 length=0 118 119 ## Prune volumes with label illformed label 120 t POST volumes/prune?filters='{"label":["tes' 500 \ 121 .cause="unexpected end of JSON input" 122 t POST libpod/volumes/prune?filters='{"label":["tes' 500 \ 123 .cause="unexpected end of JSON input" 124 125 ## Prune volumes with label matching 'testlabel' 126 t POST libpod/volumes/prune?filters='{"label":["testlabel"]}' 200 127 t GET libpod/volumes/json?filters='{"label":["testlabel"]}' 200 length=0 128 129 # libpod api: do not use list filters for prune 130 t POST libpod/volumes/prune?filters='{"name":["anyname"]}' 500 \ 131 .cause="\"name\" is an invalid volume filter" 132 t POST libpod/volumes/prune?filters='{"driver":["anydriver"]}' 500 \ 133 .cause="\"driver\" is an invalid volume filter" 134 t POST libpod/volumes/prune?filters='{"scope":["anyscope"]}' 500 \ 135 .cause="\"scope\" is an invalid volume filter" 136 137 # compat api: do not use list filters for prune 138 t POST volumes/prune?filters='{"name":["anyname"]}' 500 \ 139 .cause="\"name\" is an invalid volume filter" 140 t POST volumes/prune?filters='{"driver":["anydriver"]}' 500 \ 141 .cause="\"driver\" is an invalid volume filter" 142 t POST volumes/prune?filters='{"scope":["anyscope"]}' 500 \ 143 .cause="\"scope\" is an invalid volume filter" 144 145 ## Prune volumes using until filter 146 t POST libpod/volumes/create \ 147 Name=foo5 \ 148 Label='{"testuntil":""}' \ 149 Options='{"type":"tmpfs","o":"nodev,noexec"}}' \ 150 201 \ 151 .Name=foo5 \ 152 .Labels.testuntil="" \ 153 .Options.type=tmpfs \ 154 .Options.o=nodev,noexec 155 156 # with date way back in the past, volume should not be deleted 157 t POST libpod/volumes/prune?filters='{"until":["500000"]}' 200 158 t GET libpod/volumes/json?filters='{"label":["testuntil"]}' 200 length=1 159 160 # with date far in the future, volume should be deleted 161 t POST libpod/volumes/prune?filters='{"until":["5000000000"]}' 200 162 t GET libpod/volumes/json?filters='{"label":["testuntil"]}' 200 length=0 163 164 t POST libpod/volumes/create \ 165 Name=foo6 \ 166 Label='{"testuntilcompat":""}' \ 167 Options='{"type":"tmpfs","o":"nodev,noexec"}}' \ 168 201 \ 169 .Name=foo6 \ 170 .Labels.testuntilcompat="" \ 171 .Options.type=tmpfs \ 172 .Options.o=nodev,noexec 173 174 # with date way back in the past, volume should not be deleted (compat api) 175 t POST volumes/prune?filters='{"until":["500000"]}' 200 176 t GET libpod/volumes/json?filters='{"label":["testuntilcompat"]}' 200 length=1 177 t GET libpod/volumes/json?filters='{"until":["500000"]}' 200 length=0 178 t GET libpod/volumes/json?filters='{"until":["5000000000"]}' 200 length=1 179 180 # with date far in the future, volume should be deleted (compat api) 181 t POST volumes/prune?filters='{"until":["5000000000"]}' 200 182 t GET libpod/volumes/json?filters='{"label":["testuntilcompat"]}' 200 length=0 183 184 ## Prune volumes 185 t POST libpod/volumes/prune 200 186 #After prune volumes, there should be no volume existing 187 t GET libpod/volumes/json 200 length=0 188 189 # vim: filetype=sh