From 32982ea366165cde25d1002b5e1d3a40a3efaeb6 Mon Sep 17 00:00:00 2001
From: Stefan Lietzau <104021830+stefansli@users.noreply.github.com>
Date: Tue, 10 Dec 2024 17:10:48 +0100
Subject: [PATCH] Fix test_directory_push_pull_skip_unpack

Rewrite test to test the functionality to only unpack if the annotation is set.

Signed-off-by: Stefan Lietzau <104021830+stefansli@users.noreply.github.com>
---
 oras/tests/test_oras.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/oras/tests/test_oras.py b/oras/tests/test_oras.py
index 75a0f2c..ebb8e6e 100644
--- a/oras/tests/test_oras.py
+++ b/oras/tests/test_oras.py
@@ -2,12 +2,14 @@
 __copyright__ = "Copyright The ORAS Authors."
 __license__ = "Apache-2.0"
 
+import json
 import os
 import shutil
 
 import pytest
 
 import oras.client
+import oras.oci
 
 here = os.path.abspath(os.path.dirname(__file__))
 
@@ -168,14 +170,18 @@ def test_directory_push_pull_skip_unpack(tmp_path, registry, credentials, target
     """
     client = oras.client.OrasClient(hostname=registry, insecure=True)
 
-    # Test upload of a directory
+    # Test upload of a directory with an annotation file setting oras.defaults.annotation_unpack to False
     upload_dir = os.path.join(here, "upload_data")
-    res = client.push(files=[upload_dir], target=target_dir)
+    annotation_file = os.path.join(here, "annotations.json")
+    with open(annotation_file, "w") as f:
+        json.dump({str(upload_dir):{"oras.defaults.annotation_unpack": "False"}}, f)
+    
+    res = client.push(files=[upload_dir], target=target_dir, annotation_file=annotation_file)
     assert res.status_code == 201
-    files = client.pull(target=target_dir, outdir=tmp_path, skip_unpack=True)
+    files = client.pull(target=target_dir, outdir=tmp_path)
 
     assert len(files) == 1
-    assert os.path.basename(files[0]) == "upload_data.tar.gz"
+    assert os.path.basename(files[0]) == os.path.basename(upload_dir)
     assert str(tmp_path) in files[0]
     assert os.path.exists(files[0])