Skip to content

Commit cb32aff

Browse files
committed
test(nixos/s3-binary-cache-store): test narinfo/ls/log compression
1 parent b4f0cb4 commit cb32aff

File tree

1 file changed

+78
-1
lines changed

1 file changed

+78
-1
lines changed

tests/nixos/s3-binary-cache-store.nix

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ let
99
pkgs = config.nodes.client.nixpkgs.pkgs;
1010

1111
pkgA = pkgs.cowsay;
12+
pkgB = pkgs.busybox;
13+
pkgC = pkgs.hello;
1214

1315
accessKey = "BKIKJAA5BMMU2RHO6IBB";
1416
secretKey = "V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12";
@@ -32,7 +34,11 @@ in
3234
}:
3335
{
3436
virtualisation.writableStore = true;
35-
virtualisation.additionalPaths = [ pkgA ];
37+
virtualisation.additionalPaths = [
38+
pkgA
39+
pkgB
40+
pkgC
41+
];
3642
environment.systemPackages = [ pkgs.minio-client ];
3743
nix.extraOptions = ''
3844
experimental-features = nix-command
@@ -227,5 +233,76 @@ in
227233
print("Debug output:")
228234
print(concurrent_output)
229235
raise Exception(f"FAILED: Expected at least 5 FileTransfer instances for 5 concurrent fetches, but got {concurrent_transfers}")
236+
237+
# Test S3-specific compression functionality
238+
print("Testing S3 compression features")
239+
240+
# Create a separate bucket for compression tests
241+
server.succeed("mc mb minio/compressed-cache")
242+
compressed_store_url = "s3://compressed-cache?endpoint=http://server:9000&region=eu-west-1"
243+
244+
# Test 1: Upload with narinfo compression (gzip)
245+
print("TEST: S3 narinfo compression (gzip)")
246+
server.succeed(f"${env} nix copy --to '{compressed_store_url}&narinfo-compression=gzip' ${pkgB}")
247+
248+
# Verify the .narinfo file has Content-Encoding header
249+
pkgB_hash = "${pkgB}".split("/")[-1].split("-")[0]
250+
narinfo_path = pkgB_hash + ".narinfo"
251+
stat_output = server.succeed("mc stat minio/compressed-cache/" + narinfo_path)
252+
if "Content-Encoding" not in stat_output or "gzip" not in stat_output:
253+
print("mc stat output:")
254+
print(stat_output)
255+
raise Exception("Expected Content-Encoding: gzip header on .narinfo file")
256+
print("PASS: .narinfo has Content-Encoding: gzip")
257+
258+
# Verify client can download and decompress
259+
client.succeed(f"${env} nix copy --from '{compressed_store_url}' --no-check-sigs ${pkgB}")
260+
client.succeed("nix path-info ${pkgB}")
261+
print("PASS: Client downloaded and decompressed .narinfo successfully")
262+
263+
# Test 2: Upload with multiple compression methods
264+
print("TEST: S3 mixed compression (narinfo=xz, ls=gzip)")
265+
server.succeed(
266+
f"${env} nix copy --to '{compressed_store_url}&narinfo-compression=xz&write-nar-listing=true&ls-compression=gzip' ${pkgC}"
267+
)
268+
269+
# Verify .narinfo has xz Content-Encoding
270+
pkgC_hash = "${pkgC}".split("/")[-1].split("-")[0]
271+
narinfo_stat = server.succeed("mc stat minio/compressed-cache/" + pkgC_hash + ".narinfo")
272+
if "Content-Encoding" not in narinfo_stat or "xz" not in narinfo_stat:
273+
print("mc stat output:")
274+
print(narinfo_stat)
275+
raise Exception("Expected Content-Encoding: xz header on .narinfo file")
276+
print("PASS: .narinfo has Content-Encoding: xz")
277+
278+
# Verify .ls file has gzip Content-Encoding
279+
ls_stat = server.succeed("mc stat minio/compressed-cache/" + pkgC_hash + ".ls")
280+
if "Content-Encoding" not in ls_stat or "gzip" not in ls_stat:
281+
print("mc stat output:")
282+
print(ls_stat)
283+
raise Exception("Expected Content-Encoding: gzip header on .ls file")
284+
print("PASS: .ls has Content-Encoding: gzip")
285+
286+
# Verify client can download with mixed compression
287+
client.succeed(f"${env} nix copy --from '{compressed_store_url}' --no-check-sigs ${pkgC}")
288+
client.succeed("nix path-info ${pkgC}")
289+
print("PASS: Client downloaded package with mixed compression")
290+
291+
# Test 3: No compression by default (reuse pkgA which is already in additionalPaths)
292+
print("TEST: S3 no compression by default")
293+
server.succeed("mc mb minio/uncompressed-cache")
294+
uncompressed_url = "s3://uncompressed-cache?endpoint=http://server:9000&region=eu-west-1"
295+
server.succeed(f"${env} nix copy --to '{uncompressed_url}' ${pkgA}")
296+
297+
# Verify .narinfo does NOT have Content-Encoding header
298+
pkgA_hash = "${pkgA}".split("/")[-1].split("-")[0]
299+
narinfo_uncompressed = server.succeed("mc stat minio/uncompressed-cache/" + pkgA_hash + ".narinfo")
300+
if "Content-Encoding" in narinfo_uncompressed and ("gzip" in narinfo_uncompressed or "xz" in narinfo_uncompressed):
301+
print("mc stat output:")
302+
print(narinfo_uncompressed)
303+
raise Exception(".narinfo should not have compression Content-Encoding by default")
304+
print("PASS: No compression applied by default")
305+
306+
print("All S3 compression tests passed!")
230307
'';
231308
}

0 commit comments

Comments
 (0)