mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
813c113b9e
solves #9388 This utilizes nixos vm tests to allow: - writing tests for fetchTree and fetchGit involving actual networking. - writing small independent test cases by automating local and remote repository setup per test case. This adds: - a gitea module setting up a gitea server - a setup module that simplifies writing test cases by automating the repo setup. - a simple git http test case Other improvements: For all nixos tests, add capability of overriding the nix version to test against. This should make it easier to prevent regressions. If a new test is added it can simply be ran against any older nix version without having to backport the test. For example, for running the container tests against nix 2.12.0: `nix build "$(nix eval --raw .#hydraJobs.tests.containers --impure --apply 't: (t.forNix "2.12.0").drvPath')^*" -L`
60 lines
1.6 KiB
Nix
60 lines
1.6 KiB
Nix
{ lib, config, ... }:
|
|
{
|
|
name = "fetch-git";
|
|
|
|
imports = [
|
|
./testsupport/gitea.nix
|
|
];
|
|
|
|
/*
|
|
Test cases
|
|
The following is set up automatically for each test case:
|
|
- a repo with the {name} is created on the gitea server
|
|
- a repo with the {name} is created on the client
|
|
- the client repo is configured to push to the server repo
|
|
Python variables:
|
|
- repo.path: the path to the directory of the client repo
|
|
- repo.git: the git command with the client repo as the working directory
|
|
- repo.remote: the url to the server repo
|
|
*/
|
|
testCases = [
|
|
{
|
|
name = "simple-http";
|
|
description = "can fetch a git repo via http";
|
|
script = ''
|
|
# add a file to the repo
|
|
client.succeed(f"""
|
|
echo chiang-mai > {repo.path}/thailand \
|
|
&& {repo.git} add thailand \
|
|
&& {repo.git} commit -m 'commit1'
|
|
""")
|
|
|
|
# memoize the revision
|
|
rev1 = client.succeed(f"""
|
|
{repo.git} rev-parse HEAD
|
|
""").strip()
|
|
|
|
# push to the server
|
|
client.succeed(f"""
|
|
{repo.git} push origin main
|
|
""")
|
|
|
|
# fetch the repo via nix
|
|
fetched1 = client.succeed(f"""
|
|
nix eval --impure --raw --expr "(builtins.fetchGit {repo.remote}).outPath"
|
|
""")
|
|
|
|
# check if the committed file is there
|
|
client.succeed(f"""
|
|
test -f {fetched1}/thailand
|
|
""")
|
|
|
|
# check if the revision is the same
|
|
rev1_fetched = client.succeed(f"""
|
|
nix eval --impure --raw --expr "(builtins.fetchGit {repo.remote}).rev"
|
|
""").strip()
|
|
assert rev1 == rev1_fetched
|
|
'';
|
|
}
|
|
];
|
|
}
|