1313from cryptography .hazmat .primitives .asymmetric import rsa
1414from dotenv import load_dotenv
1515
16- from .constants import TEST_DATA_DIR , GL_ROOT_DIR , CERT_DIR
17- from .helper import call_command , spawn_background_process , generate_test_certificates
16+ from .constants import (
17+ TEST_DATA_DIR ,
18+ GL_ROOT_DIR ,
19+ CERT_DIR ,
20+ GARDENLINUX_ROOT_DIR_EXAMPLE ,
21+ TEST_COMMIT ,
22+ TEST_VERSION ,
23+ TEST_PLATFORMS ,
24+ TEST_FEATURE_SET ,
25+ TEST_FEATURE_STRINGS_SHORT ,
26+ TEST_ARCHITECTURES ,
27+ )
28+ from .helper import call_command , spawn_background_process
1829
1930
2031def generate_test_certificates ():
@@ -73,6 +84,48 @@ def write_zot_config(config_dict, file_path):
7384 json .dump (config_dict , config_file , indent = 4 )
7485
7586
87+ def create_test_data ():
88+ """Generate test data for OCI registry tests (replaces build-test-data.sh)"""
89+ print ("Creating fake artifacts..." )
90+
91+ # Ensure the build directory exists
92+ os .makedirs (GARDENLINUX_ROOT_DIR_EXAMPLE , exist_ok = True )
93+
94+ # Generate test artifacts for each combination
95+ for platform in TEST_PLATFORMS :
96+ for feature_string in TEST_FEATURE_STRINGS_SHORT :
97+ for arch in TEST_ARCHITECTURES :
98+ # Base name for the artifact
99+ cname = (
100+ f"{ platform } -{ feature_string } -{ arch } -{ TEST_VERSION } -{ TEST_COMMIT } "
101+ )
102+
103+ print ("Building mocked test data..." )
104+ # Create release file with metadata
105+ release_file = f"{ GARDENLINUX_ROOT_DIR_EXAMPLE } /{ cname } .release"
106+ with open (release_file , "w" ) as f :
107+ f .write (f"GARDENLINUX_FEATURES={ TEST_FEATURE_SET } \n " )
108+ f .write (f"GARDENLINUX_COMMIT_ID={ TEST_COMMIT } \n " )
109+
110+ # Create various file formats
111+ for ext in ["raw" , "tar" , "qcow2" , "vmdk" ]:
112+ file_path = f"{ GARDENLINUX_ROOT_DIR_EXAMPLE } /{ cname } .{ ext } "
113+ with open (file_path , "w" ) as f :
114+ f .write (f"dummy content for { file_path } " )
115+
116+ # Create platform-specific files
117+ if platform == "gcp" :
118+ for ext in ["tar.gz" , "gcpimage.tar.gz" ]:
119+ file_path = f"{ GARDENLINUX_ROOT_DIR_EXAMPLE } /{ cname } .{ ext } "
120+ with open (file_path , "w" ) as f :
121+ f .write (f"dummy content for { file_path } " )
122+
123+ if platform == "azure" :
124+ file_path = f"{ GARDENLINUX_ROOT_DIR_EXAMPLE } /{ cname } .vhd"
125+ with open (file_path , "w" ) as f :
126+ f .write (f"dummy content for { file_path } " )
127+
128+
76129@pytest .fixture (autouse = False , scope = "function" )
77130def zot_session ():
78131 load_dotenv ()
@@ -108,8 +161,9 @@ def zot_session():
108161
109162def pytest_sessionstart (session ):
110163 generate_test_certificates ()
111- call_command ("./test-data/build-test-data.sh --dummy" )
112- call_command ("mkdir -p manifests" )
164+ # Replace the bash script call with our Python function
165+ create_test_data ()
166+ os .makedirs ("./manifests" , exist_ok = True )
113167
114168
115169def pytest_sessionfinish (session ):
@@ -119,3 +173,5 @@ def pytest_sessionfinish(session):
119173 os .remove (CERT_DIR + "/oci-sign.key" )
120174 if os .path .isdir ("./manifests" ):
121175 shutil .rmtree ("./manifests" )
176+ if os .path .isdir (GARDENLINUX_ROOT_DIR_EXAMPLE ):
177+ shutil .rmtree (GARDENLINUX_ROOT_DIR_EXAMPLE )
0 commit comments