MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / get_test_image_dir

Function get_test_image_dir

dstack-mr/tests/tdvf_parse.rs:31–75  ·  view source on GitHub ↗

Download and extract dstack release tarball if not already cached

()

Source from the content-addressed store, hash-verified

29
30/// Download and extract dstack release tarball if not already cached
31fn get_test_image_dir() -> Result<PathBuf> {
32 let cache_dir = std::env::temp_dir().join("dstack-mr-test-cache");
33 let version_dir = cache_dir.join(DSTACK_VERSION);
34 let image_dir = version_dir.join("dstack-0.5.5");
35 let metadata_path = image_dir.join("metadata.json");
36
37 // Return cached version if it exists
38 if metadata_path.exists() {
39 return Ok(image_dir);
40 }
41
42 eprintln!("Downloading dstack {DSTACK_VERSION} release for testing...",);
43 std::fs::create_dir_all(&version_dir)?;
44
45 // Download tarball
46 let tarball_path = version_dir.join("dstack.tar.gz");
47 let response =
48 reqwest::blocking::get(DSTACK_RELEASE_URL).context("failed to download dstack release")?;
49
50 if !response.status().is_success() {
51 anyhow::bail!("failed to download: HTTP {}", response.status());
52 }
53
54 let bytes = response.bytes().context("failed to read response")?;
55 std::fs::write(&tarball_path, bytes).context("failed to write tarball")?;
56
57 eprintln!("Extracting tarball...");
58
59 // Extract tarball
60 let tarball = std::fs::File::open(&tarball_path)?;
61 let decoder = flate2::read::GzDecoder::new(tarball);
62 let mut archive = tar::Archive::new(decoder);
63 archive
64 .unpack(&version_dir)
65 .context("failed to extract tarball")?;
66
67 // Verify extraction
68 if !metadata_path.exists() {
69 anyhow::bail!("metadata.json not found after extraction");
70 }
71
72 eprintln!("Test image ready at: {}", image_dir.display());
73
74 Ok(image_dir)
75}
76
77#[test]
78#[ignore] // Run with: cargo test --release -- --ignored

Calls 2

bytesMethod · 0.80
statusMethod · 0.45

Tested by

no test coverage detected