Skip to content

Commit

Permalink
e2e test for gitlfs
Browse files Browse the repository at this point in the history
  • Loading branch information
b-camacho committed Nov 6, 2024
1 parent d2d6f20 commit 75a1ba3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
70 changes: 70 additions & 0 deletions tests/nixos/fetch-git/test-cases/lfs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
# mostly copied from https://github.com/NixOS/nix/blob/358c26fd13a902d9a4032a00e6683571be07a384/tests/nixos/fetch-git/test-cases/fetchTree-shallow/default.nix#L1
# ty @DavHau
description = "fetchGit with lfs=true smudges LFS pointers";
script = ''
# purge nix git cache to make sure we start with a clean slate
client.succeed("rm -rf ~/.cache/nix")
# add two commits to the repo:
client.succeed(f"""
dd if=/dev/urandom of={repo.path}/beeg bs=1M count=1 \
&& {repo.git} lfs track "beeg" \
&& {repo.git} add .gitattributes \
&& {repo.git} add beeg \
&& {repo.git} commit -m 'commit1' \
&& {repo.git} push origin main
""")
# memoize the revision
commit1_rev = client.succeed(f"""
{repo.git} rev-parse HEAD
""").strip()
# first fetch without lfs, check that we did not smudge the file
fetchGit_nolfs_expr = f"""
builtins.fetchGit {{
type = "git";
url = "{repo.remote}";
rev = "{commit1_rev}";
lfs = false;
}}
"""
# fetch the repo via nix
fetched_nolfs = client.succeed(f"""
nix eval --impure --raw --expr '({fetchGit_nolfs_expr}).outPath'
""")
# check that file was not smudged
file_size_nolfs = client.succeed(f"""
stat -c %s {fetched_nolfs}/beeg
""").strip()
expected_max_size_lfs = 1024
assert int(file_size_nolfs) < expected_max_size_lfs, f"lfs-enrolled file bigger than {expected_max_size_lfs}, file was probably smudged but we did not set lfs=true"
# now fetch with lfs=true and check that the file was smudged
fetchGit_lfs_expr = f"""
builtins.fetchGit {{
type = "git";
url = "{repo.remote}";
rev = "{commit1_rev}";
lfs = true;
}}
"""
# fetch the repo via nix
fetched_lfs = client.succeed(f"""
nix eval --impure --raw --expr '({fetchGit_lfs_expr}).outPath'
""")
# check that file was smudged
file_size_lfs = client.succeed(f"""
stat -c %s {fetched_lfs}/beeg
""").strip()
expected_min_size_lfs = 1024 * 1024 # 1MB
assert int(file_size_lfs) >= expected_min_size_lfs, f"lfs-enrolled file smaller than {expected_min_size_lfs}, file was probably not smudged despite lfs=true"
'';
}
2 changes: 1 addition & 1 deletion tests/nixos/fetch-git/testsupport/gitea.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ in {
});
};
client = { pkgs, ... }: {
environment.systemPackages = [ pkgs.git ];
environment.systemPackages = [ pkgs.git pkgs.git-lfs ];
};
};
defaults = { pkgs, ... }: {
Expand Down

0 comments on commit 75a1ba3

Please sign in to comment.