mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
Rework tests
This commit is contained in:
parent
b1663fa3fb
commit
726f8fd61f
1 changed files with 152 additions and 157 deletions
|
@ -5,15 +5,13 @@
|
||||||
script = ''
|
script = ''
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
expected_max_size_lfs_pointer = 1024 # 1 KiB (values >= than this cannot be pointers, and test files are >= 1 MiB)
|
expected_max_size_lfs_pointer = 1024 # 1 KiB (values >= than this cannot be pointers, and test files are 1 MiB)
|
||||||
|
|
||||||
# purge nix git cache to make sure we start with a clean slate
|
# purge nix git cache to make sure we start with a clean slate
|
||||||
client.succeed("rm -rf ~/.cache/nix")
|
client.succeed("rm -rf ~/.cache/nix")
|
||||||
|
|
||||||
|
|
||||||
# Request lfs fetch without any .gitattributes file
|
with subtest("Request lfs fetch without any .gitattributes file"):
|
||||||
############################################################################
|
|
||||||
|
|
||||||
client.succeed(f"dd if=/dev/urandom of={repo.path}/regular bs=1M count=1 >&2")
|
client.succeed(f"dd if=/dev/urandom of={repo.path}/regular bs=1M count=1 >&2")
|
||||||
client.succeed(f"{repo.git} add : >&2")
|
client.succeed(f"{repo.git} add : >&2")
|
||||||
client.succeed(f"{repo.git} commit -m 'no .gitattributes' >&2")
|
client.succeed(f"{repo.git} commit -m 'no .gitattributes' >&2")
|
||||||
|
@ -32,15 +30,14 @@
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
fetched_no_gitattributes = client.succeed(f"""
|
fetched_no_gitattributes = client.succeed(f"""
|
||||||
nix eval --impure --raw --expr '({fetchGit_no_gitattributes_expr}).outPath'
|
nix eval --debug --impure --raw --expr '({fetchGit_no_gitattributes_expr}).outPath'
|
||||||
""")
|
""")
|
||||||
client.succeed(f"cmp {repo.path}/regular {fetched_no_gitattributes}/regular >&2")
|
client.succeed(f"cmp {repo.path}/regular {fetched_no_gitattributes}/regular >&2")
|
||||||
|
|
||||||
|
|
||||||
# Add a file that should be tracked by lfs, but isn't
|
with subtest("Add a file that should be tracked by lfs, but isn't"):
|
||||||
# (git lfs cli only throws a warning "Encountered 1 file that should have
|
# (git lfs cli only throws a warning "Encountered 1 file that should have
|
||||||
# been a pointer, but wasn't")
|
# been a pointer, but wasn't")
|
||||||
############################################################################
|
|
||||||
|
|
||||||
client.succeed(f"dd if=/dev/urandom of={repo.path}/black_sheep bs=1M count=1 >&2")
|
client.succeed(f"dd if=/dev/urandom of={repo.path}/black_sheep bs=1M count=1 >&2")
|
||||||
client.succeed(f"echo 'black_sheep filter=lfs -text' >>{repo.path}/.gitattributes")
|
client.succeed(f"echo 'black_sheep filter=lfs -text' >>{repo.path}/.gitattributes")
|
||||||
|
@ -60,8 +57,8 @@
|
||||||
|
|
||||||
# check that the file is not a pointer, as expected
|
# check that the file is not a pointer, as expected
|
||||||
file_size_git = client.succeed(f"stat -c %s {tempdir}/black_sheep").strip()
|
file_size_git = client.succeed(f"stat -c %s {tempdir}/black_sheep").strip()
|
||||||
assert int(file_size_git) >= expected_max_size_lfs_pointer, \
|
assert int(file_size_git) == 1024 * 1024, \
|
||||||
f"non lfs file is {file_size_git}b (<{expected_max_size_lfs_pointer}b), probably a test implementation error"
|
f"non lfs file is {file_size_git}b (!= 1MiB), probably a test implementation error"
|
||||||
|
|
||||||
lfs_files = client.succeed(f"git -C {tempdir} lfs ls-files").strip()
|
lfs_files = client.succeed(f"git -C {tempdir} lfs ls-files").strip()
|
||||||
assert lfs_files == "", "non lfs file is tracked by lfs, probably a test implementation error"
|
assert lfs_files == "", "non lfs file is tracked by lfs, probably a test implementation error"
|
||||||
|
@ -78,14 +75,14 @@
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
fetched_bad_lfs_without_lfs = client.succeed(f"""
|
fetched_bad_lfs_without_lfs = client.succeed(f"""
|
||||||
nix eval --impure --raw --expr '({fetchGit_bad_lfs_without_lfs_expr}).outPath'
|
nix eval --debug --impure --raw --expr '({fetchGit_bad_lfs_without_lfs_expr}).outPath'
|
||||||
""")
|
""")
|
||||||
|
|
||||||
# check that file was not somehow turned into a pointer
|
# check that file was not somehow turned into a pointer
|
||||||
file_size_bad_lfs_without_lfs = client.succeed(f"stat -c %s {fetched_bad_lfs_without_lfs}/black_sheep").strip()
|
file_size_bad_lfs_without_lfs = client.succeed(f"stat -c %s {fetched_bad_lfs_without_lfs}/black_sheep").strip()
|
||||||
|
|
||||||
assert int(file_size_bad_lfs_without_lfs) >= expected_max_size_lfs_pointer, \
|
assert int(file_size_bad_lfs_without_lfs) == 1024 * 1024, \
|
||||||
f"non lfs-enrolled file is {file_size_bad_lfs_without_lfs}b (<{expected_max_size_lfs_pointer}b), probably a test implementation error"
|
f"non lfs-enrolled file is {file_size_bad_lfs_without_lfs}b (!= 1MiB), probably a test implementation error"
|
||||||
client.succeed(f"cmp {repo.path}/black_sheep {fetched_bad_lfs_without_lfs}/black_sheep >&2")
|
client.succeed(f"cmp {repo.path}/black_sheep {fetched_bad_lfs_without_lfs}/black_sheep >&2")
|
||||||
|
|
||||||
# finally fetch with lfs=true, and check that the bad file does not break anything
|
# finally fetch with lfs=true, and check that the bad file does not break anything
|
||||||
|
@ -98,15 +95,13 @@
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
fetchGit_bad_lfs_with_lfs = client.succeed(f"""
|
fetchGit_bad_lfs_with_lfs = client.succeed(f"""
|
||||||
nix eval --impure --raw --expr '({fetchGit_bad_lfs_with_lfs_expr}).outPath'
|
nix eval --debug --impure --raw --expr '({fetchGit_bad_lfs_with_lfs_expr}).outPath'
|
||||||
""")
|
""")
|
||||||
|
|
||||||
client.succeed(f"cmp {repo.path}/black_sheep {fetchGit_bad_lfs_with_lfs}/black_sheep >&2")
|
client.succeed(f"cmp {repo.path}/black_sheep {fetchGit_bad_lfs_with_lfs}/black_sheep >&2")
|
||||||
|
|
||||||
|
|
||||||
# Add an lfs-enrolled file to the repo
|
with subtest("Add an lfs-enrolled file to the repo"):
|
||||||
############################################################################
|
|
||||||
|
|
||||||
client.succeed(f"dd if=/dev/urandom of={repo.path}/beeg bs=1M count=1 >&2")
|
client.succeed(f"dd if=/dev/urandom of={repo.path}/beeg bs=1M count=1 >&2")
|
||||||
client.succeed(f"{repo.git} lfs install >&2")
|
client.succeed(f"{repo.git} lfs install >&2")
|
||||||
client.succeed(f"{repo.git} lfs track --filename beeg >&2")
|
client.succeed(f"{repo.git} lfs track --filename beeg >&2")
|
||||||
|
@ -127,14 +122,14 @@
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
fetched_nolfs = client.succeed(f"""
|
fetched_nolfs = client.succeed(f"""
|
||||||
nix eval --impure --raw --expr '({fetchGit_nolfs_expr}).outPath'
|
nix eval --debug --impure --raw --expr '({fetchGit_nolfs_expr}).outPath'
|
||||||
""")
|
""")
|
||||||
|
|
||||||
# check that file was not smudged
|
# check that file was not smudged
|
||||||
file_size_nolfs = client.succeed(f"stat -c %s {fetched_nolfs}/beeg").strip()
|
file_size_nolfs = client.succeed(f"stat -c %s {fetched_nolfs}/beeg").strip()
|
||||||
|
|
||||||
assert int(file_size_nolfs) < expected_max_size_lfs_pointer, \
|
assert int(file_size_nolfs) < expected_max_size_lfs_pointer, \
|
||||||
f"did not set lfs=true, yet lfs-enrolled file is {file_size_nolfs}b (>{expected_max_size_lfs_pointer}b), probably smudged when we should not have"
|
f"did not set lfs=true, yet lfs-enrolled file is {file_size_nolfs}b (>= 1KiB), probably smudged when we should not have"
|
||||||
|
|
||||||
# now fetch with lfs=true and check that the file was smudged
|
# now fetch with lfs=true and check that the file was smudged
|
||||||
fetchGit_lfs_expr = f"""
|
fetchGit_lfs_expr = f"""
|
||||||
|
@ -146,7 +141,7 @@
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
fetched_lfs = client.succeed(f"""
|
fetched_lfs = client.succeed(f"""
|
||||||
nix eval --impure --raw --expr '({fetchGit_lfs_expr}).outPath'
|
nix eval --debug --impure --raw --expr '({fetchGit_lfs_expr}).outPath'
|
||||||
""")
|
""")
|
||||||
|
|
||||||
assert fetched_lfs != fetched_nolfs, \
|
assert fetched_lfs != fetched_nolfs, \
|
||||||
|
@ -154,12 +149,11 @@
|
||||||
|
|
||||||
# check that file was smudged
|
# check that file was smudged
|
||||||
file_size_lfs = client.succeed(f"stat -c %s {fetched_lfs}/beeg").strip()
|
file_size_lfs = client.succeed(f"stat -c %s {fetched_lfs}/beeg").strip()
|
||||||
assert int(file_size_lfs) >= expected_max_size_lfs_pointer, \
|
assert int(file_size_lfs) == 1024 * 1024, \
|
||||||
f"set lfs=true, yet lfs-enrolled file is {file_size_lfs}b (<{expected_max_size_lfs_pointer}), probably did not smudge when we should have"
|
f"set lfs=true, yet lfs-enrolled file is {file_size_lfs}b (!= 1MiB), probably did not smudge when we should have"
|
||||||
|
|
||||||
|
|
||||||
# Check that default is lfs=false
|
with subtest("Check that default is lfs=false"):
|
||||||
############################################################################
|
|
||||||
fetchGit_default_expr = f"""
|
fetchGit_default_expr = f"""
|
||||||
builtins.fetchGit {{
|
builtins.fetchGit {{
|
||||||
url = "{repo.remote}";
|
url = "{repo.remote}";
|
||||||
|
@ -168,17 +162,18 @@
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
fetched_default = client.succeed(f"""
|
fetched_default = client.succeed(f"""
|
||||||
nix eval --impure --raw --expr '({fetchGit_default_expr}).outPath'
|
nix eval --debug --impure --raw --expr '({fetchGit_default_expr}).outPath'
|
||||||
""")
|
""")
|
||||||
|
|
||||||
# check that file was not smudged
|
# check that file was not smudged
|
||||||
file_size_default = client.succeed(f"stat -c %s {fetched_default}/beeg").strip()
|
file_size_default = client.succeed(f"stat -c %s {fetched_default}/beeg").strip()
|
||||||
|
|
||||||
assert int(file_size_default) < expected_max_size_lfs_pointer, \
|
assert int(file_size_default) < expected_max_size_lfs_pointer, \
|
||||||
f"did not set lfs, yet lfs-enrolled file is {file_size_default}b (>{expected_max_size_lfs_pointer}b), probably bad default value"
|
f"did not set lfs, yet lfs-enrolled file is {file_size_default}b (>= 1KiB), probably bad default value"
|
||||||
|
|
||||||
# Use as flake input
|
with subtest("Use as flake input"):
|
||||||
############################################################################
|
# May seem reduntant, but this has minor differences compared to raw
|
||||||
|
# fetchGit which caused failures before
|
||||||
with TemporaryDirectory() as tempdir:
|
with TemporaryDirectory() as tempdir:
|
||||||
client.succeed(f"mkdir -p {tempdir}")
|
client.succeed(f"mkdir -p {tempdir}")
|
||||||
client.succeed(f"""
|
client.succeed(f"""
|
||||||
|
@ -193,7 +188,7 @@
|
||||||
}}' >{tempdir}/flake.nix
|
}}' >{tempdir}/flake.nix
|
||||||
""")
|
""")
|
||||||
fetched_flake = client.succeed(f"""
|
fetched_flake = client.succeed(f"""
|
||||||
nix eval --raw {tempdir}#.outPath
|
nix eval --debug --raw {tempdir}#.outPath
|
||||||
""")
|
""")
|
||||||
|
|
||||||
assert fetched_lfs == fetched_flake, \
|
assert fetched_lfs == fetched_flake, \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue