Skip to content

Commit

Permalink
containerized_test: create test module
Browse files Browse the repository at this point in the history
Create new containerized test module focused
in containerized deployment. This test will check
uploading and downloading with a containerized
imageio version.

Initial version only tests that starting a server
with an initial ticket works, and we can upload
and download with that server.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
  • Loading branch information
aesteve-rh authored and nirs committed Sep 29, 2022
1 parent 56d1ed7 commit 32855ab
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/containerized_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2022 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

import json
import http.client as http_client

from ovirt_imageio._internal import config
from ovirt_imageio._internal import server
from ovirt_imageio._internal.units import KiB

from . import testutil
from . import http


TICKET_SIZE = 16 * KiB


def test_start_with_ticket(tmpdir):
# Create ticket
image = testutil.create_tempfile(tmpdir, name="disk.raw", size=TICKET_SIZE)
ticket = testutil.create_ticket(size=TICKET_SIZE, url=f'file://{image}')
ticket_id = ticket['uuid']
ticket_path = tmpdir.join("file.json")
ticket_path.write(json.dumps(ticket))

# Start server with ticket
cfg = config.load("test/conf/daemon.conf")
srv = server.Server(cfg, ticket=ticket_path)
srv.start()
try:
data = b"a" * (TICKET_SIZE // 2) + b"b" * (TICKET_SIZE // 2)
# Test that we can upload
with http.RemoteClient(srv.config) as c:
res = c.put(f'/images/{ticket_id}', data)
assert res.status == http_client.OK
# Test that we can download and matches the uploaded data
with http.RemoteClient(srv.config) as c:
res = c.get(f'/images/{ticket_id}')
assert res.read() == data
assert res.status == http_client.OK
finally:
srv.stop()

0 comments on commit 32855ab

Please sign in to comment.