mirror of
https://github.com/containers/podman.git
synced 2025-06-19 16:33:24 +08:00
Jira RUN-1106 Volumes handlers updates
* Add tests to verify required fields in responses Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -223,7 +223,7 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
} else {
|
||||
// Success
|
||||
utils.WriteResponse(w, http.StatusNoContent, "")
|
||||
utils.WriteResponse(w, http.StatusNoContent, nil)
|
||||
}
|
||||
} else {
|
||||
if !query.Force {
|
||||
@ -232,7 +232,7 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) {
|
||||
// Volume does not exist and `force` is truthy - this emulates what
|
||||
// Docker would do when told to `force` removal of a nonextant
|
||||
// volume
|
||||
utils.WriteResponse(w, http.StatusNoContent, "")
|
||||
utils.WriteResponse(w, http.StatusNoContent, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -423,6 +423,57 @@ class TestApi(unittest.TestCase):
|
||||
prune = requests.post(PODMAN_URL + "/v1.40/networks/prune")
|
||||
self.assertEqual(prune.status_code, 405, prune.content)
|
||||
|
||||
def test_volumes_compat(self):
|
||||
name = "Volume_" + "".join(random.choice(string.ascii_letters) for i in range(10))
|
||||
|
||||
ls = requests.get(PODMAN_URL + "/v1.40/volumes")
|
||||
self.assertEqual(ls.status_code, 200, ls.content)
|
||||
|
||||
# See https://docs.docker.com/engine/api/v1.40/#operation/VolumeList
|
||||
required_keys = (
|
||||
"Volumes",
|
||||
"Warnings",
|
||||
)
|
||||
|
||||
obj = json.loads(ls.content)
|
||||
self.assertIn(type(obj), (dict,))
|
||||
for k in required_keys:
|
||||
self.assertIn(k, obj)
|
||||
|
||||
create = requests.post(PODMAN_URL + "/v1.40/volumes/create", json={"Name": name})
|
||||
self.assertEqual(create.status_code, 201, create.content)
|
||||
|
||||
# See https://docs.docker.com/engine/api/v1.40/#operation/VolumeCreate
|
||||
# and https://docs.docker.com/engine/api/v1.40/#operation/VolumeInspect
|
||||
required_keys = (
|
||||
"Name",
|
||||
"Driver",
|
||||
"Mountpoint",
|
||||
"Labels",
|
||||
"Scope",
|
||||
"Options",
|
||||
)
|
||||
|
||||
obj = json.loads(create.content)
|
||||
self.assertIn(type(obj), (dict,))
|
||||
for k in required_keys:
|
||||
self.assertIn(k, obj)
|
||||
self.assertEqual(obj["Name"], name)
|
||||
|
||||
inspect = requests.get(PODMAN_URL + f"/v1.40/volumes/{name}")
|
||||
self.assertEqual(inspect.status_code, 200, inspect.content)
|
||||
|
||||
obj = json.loads(create.content)
|
||||
self.assertIn(type(obj), (dict,))
|
||||
for k in required_keys:
|
||||
self.assertIn(k, obj)
|
||||
|
||||
rm = requests.delete(PODMAN_URL + f"/v1.40/volumes/{name}")
|
||||
self.assertEqual(rm.status_code, 204, rm.content)
|
||||
|
||||
prune = requests.post(PODMAN_URL + "/v1.40/volumes/prune")
|
||||
self.assertEqual(prune.status_code, 200, prune.content)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user