From a58cfcd1aa7019ce118b44c389c00980ccac021f Mon Sep 17 00:00:00 2001 From: Di Chen Date: Tue, 15 Feb 2022 14:39:52 +0800 Subject: [PATCH] reftest: support absent items --- support/reftest/data.yml | 2 ++ support/reftest/reftest | 26 +++++++++++++++++++++++++- tests/integration/test_exodus.py | 13 +++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/support/reftest/data.yml b/support/reftest/data.yml index 4147ba21..61b6aa7f 100644 --- a/support/reftest/data.yml +++ b/support/reftest/data.yml @@ -41,3 +41,5 @@ test_data: - path: /content/dist/rhel/atomic/7/7Server/x86_64/ostree/repo/refs/heads/rhel-atomic-host/7/x86_64/standard content-type: text/plain - path: /content/dist/rhel8/8.2/x86_64/baseos/iso/rhel-8.2-x86_64-boot.iso +- path: /content/dist/rhel8/8.2/x86_64/baseos/iso/does-not-exist.iso + state: absent diff --git a/support/reftest/reftest b/support/reftest/reftest index c910f50d..e95c71db 100755 --- a/support/reftest/reftest +++ b/support/reftest/reftest @@ -73,6 +73,23 @@ class DBHandler: Item=item, ) + def put_absent_item(self, path, from_date=None): + if not from_date: + from_date = self.default_from_date + + item = { + "web_uri": {"S": path}, + "from_date": {"S": from_date}, + "object_key": {"S": "absent"}, + "content_type": {"S": ""}, + "metadata": {"M": {}}, + } + + self.dynamodb.put_item( + TableName=self.table, + Item=item, + ) + class S3Handler: def __init__(self, bucket, session): @@ -242,6 +259,11 @@ def prepare(db_client, s3_client, config, opt): # skip items that specify deploy=false continue + if item.get("state") == "absent": + # skip all the downloading and checking when absent=true + db_client.put_absent_item(item["path"]) + continue + url = config.prod_cdn_url + item["path"] # download test data to local with a name "NamedTemporaryFile" temp_file, cdn_data_checksum = download_to_local( @@ -288,7 +310,9 @@ def main(): region_name=opt.default_region, ) - db_client = DBHandler(table=opt.table, config_table=opt.config_table, session=session) + db_client = DBHandler( + table=opt.table, config_table=opt.config_table, session=session + ) s3_client = S3Handler(bucket=opt.bucket, session=session) res = False diff --git a/tests/integration/test_exodus.py b/tests/integration/test_exodus.py index d897717a..94a4d9b8 100644 --- a/tests/integration/test_exodus.py +++ b/tests/integration/test_exodus.py @@ -205,3 +205,16 @@ def test_no_content_type(cdn_test_url, testdata_path): print(json.dumps(dict(r.headers), indent=2)) assert r.status_code == 200 assert r.headers["Content-Type"] == "application/octet-stream" + + +testdata_absent_item = [ + "/content/dist/rhel8/8.2/x86_64/baseos/iso/does-not-exist.iso" +] + + +@pytest.mark.parametrize("testdata_path", testdata_absent_item) +def test_absent_item(cdn_test_url, testdata_path): + url = cdn_test_url + testdata_path + r = requests.get(url) + print(json.dumps(dict(r.headers), indent=2)) + assert r.status_code == 404