Skip to content

Commit 2f7dbac

Browse files
CopilotSeriousBug
andcommitted
Fix dynamic tests to handle both always-embed and debug modes correctly
Co-authored-by: SeriousBug <1008124+SeriousBug@users.noreply.github.com>
1 parent 209aecf commit 2f7dbac

1 file changed

Lines changed: 51 additions & 18 deletions

File tree

tests/dynamic.rs

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ fn dynamic_file_compressed_data_is_none() {
1111
// In debug mode without always-embed, this should use DynamicFile
1212
let file = DynamicAssets::get("index.html").unwrap();
1313

14-
// DynamicFile always returns None for compressed data
15-
assert!(file.data_gzip().is_none());
16-
assert!(file.data_br().is_none());
17-
assert!(file.data_zstd().is_none());
14+
// When always-embed is not enabled, DynamicFile always returns None for compressed data
15+
#[cfg(not(feature = "always-embed"))]
16+
{
17+
assert!(file.data_gzip().is_none());
18+
assert!(file.data_br().is_none());
19+
assert!(file.data_zstd().is_none());
20+
}
1821

19-
// But it should still have the original data
22+
// When always-embed is enabled, EmbeddedFile may have compressed data
23+
#[cfg(feature = "always-embed")]
24+
{
25+
// Just verify the file exists and has data - compression depends on the build
26+
assert!(!file.data().is_empty());
27+
}
28+
29+
// But it should always have the original data
2030
assert!(!file.data().is_empty());
2131
}
2232

@@ -25,12 +35,22 @@ fn dynamic_file_image_compressed_data_is_none() {
2535
// Test with an image file too
2636
let file = DynamicAssets::get("images/flower.jpg").unwrap();
2737

28-
// DynamicFile always returns None for compressed data
29-
assert!(file.data_gzip().is_none());
30-
assert!(file.data_br().is_none());
31-
assert!(file.data_zstd().is_none());
38+
// When always-embed is not enabled, DynamicFile always returns None for compressed data
39+
#[cfg(not(feature = "always-embed"))]
40+
{
41+
assert!(file.data_gzip().is_none());
42+
assert!(file.data_br().is_none());
43+
assert!(file.data_zstd().is_none());
44+
}
45+
46+
// When always-embed is enabled, EmbeddedFile may have compressed data (usually None for images)
47+
#[cfg(feature = "always-embed")]
48+
{
49+
// Just verify the file exists and has data
50+
assert!(!file.data().is_empty());
51+
}
3252

33-
// But it should still have the original data
53+
// But it should always have the original data
3454
assert!(!file.data().is_empty());
3555
}
3656

@@ -39,15 +59,28 @@ fn explicit_dynamic_compression_coverage() {
3959
// Explicitly test to ensure coverage of DynamicFile compression methods
4060
let file = DynamicAssets::get("index.html").unwrap();
4161

42-
// Test each compression method explicitly to ensure coverage
43-
let gzip_result = file.data_gzip();
44-
assert_eq!(gzip_result, None);
45-
46-
let br_result = file.data_br();
47-
assert_eq!(br_result, None);
62+
// When always-embed is not enabled, test the DynamicFile paths
63+
#[cfg(not(feature = "always-embed"))]
64+
{
65+
// Test each compression method explicitly to ensure coverage
66+
let gzip_result = file.data_gzip();
67+
assert_eq!(gzip_result, None);
68+
69+
let br_result = file.data_br();
70+
assert_eq!(br_result, None);
71+
72+
let zstd_result = file.data_zstd();
73+
assert_eq!(zstd_result, None);
74+
}
4875

49-
let zstd_result = file.data_zstd();
50-
assert_eq!(zstd_result, None);
76+
// When always-embed is enabled, test the EmbeddedFile paths
77+
#[cfg(feature = "always-embed")]
78+
{
79+
// Just verify the methods work - the actual compressed data depends on build configuration
80+
let _gzip_result = file.data_gzip();
81+
let _br_result = file.data_br();
82+
let _zstd_result = file.data_zstd();
83+
}
5184

5285
// Ensure we have actual data though
5386
let actual_data = file.data();

0 commit comments

Comments
 (0)