nixos/tests/forgejo: remove one of the two clients, offload ssh & git config, refactor
We inherited almost all of this test from `nixos/tests/gitea` when we decided to split. This change saves some resources (just 2 instead of 3 VMs) and is (IMHO) easier to follow and improve upon.
This commit is contained in:
parent
ddcd5f2762
commit
45e438f5eb
|
@ -23,7 +23,7 @@ let
|
||||||
signingPrivateKeyId = "4D642DE8B678C79D";
|
signingPrivateKeyId = "4D642DE8B678C79D";
|
||||||
|
|
||||||
supportedDbTypes = [ "mysql" "postgres" "sqlite3" ];
|
supportedDbTypes = [ "mysql" "postgres" "sqlite3" ];
|
||||||
makeGForgejoTest = type: nameValuePair type (makeTest {
|
makeForgejoTest = type: nameValuePair type (makeTest {
|
||||||
name = "forgejo-${type}";
|
name = "forgejo-${type}";
|
||||||
meta.maintainers = with maintainers; [ bendlas emilylange ];
|
meta.maintainers = with maintainers; [ bendlas emilylange ];
|
||||||
|
|
||||||
|
@ -62,11 +62,20 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
client1 = { config, pkgs, ... }: {
|
client = { ... }: {
|
||||||
environment.systemPackages = [ pkgs.git ];
|
programs.git = {
|
||||||
};
|
enable = true;
|
||||||
client2 = { config, pkgs, ... }: {
|
config = {
|
||||||
environment.systemPackages = [ pkgs.git ];
|
user.email = "test@localhost";
|
||||||
|
user.name = "test";
|
||||||
|
init.defaultBranch = "main";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
programs.ssh.extraConfig = ''
|
||||||
|
Host *
|
||||||
|
StrictHostKeyChecking no
|
||||||
|
IdentityFile ~/.ssh/privk
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -75,26 +84,22 @@ let
|
||||||
inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey;
|
inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey;
|
||||||
serverSystem = nodes.server.system.build.toplevel;
|
serverSystem = nodes.server.system.build.toplevel;
|
||||||
dumpFile = with nodes.server.specialisation.dump.configuration.services.forgejo.dump; "${backupDir}/${file}";
|
dumpFile = with nodes.server.specialisation.dump.configuration.services.forgejo.dump; "${backupDir}/${file}";
|
||||||
|
remoteUri = "forgejo@server:test/repo";
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
import json
|
import json
|
||||||
GIT_SSH_COMMAND = "ssh -i $HOME/.ssh/privk -o StrictHostKeyChecking=no"
|
|
||||||
REPO = "forgejo@server:test/repo"
|
|
||||||
PRIVK = "${snakeOilPrivateKey}"
|
|
||||||
|
|
||||||
start_all()
|
start_all()
|
||||||
|
|
||||||
client1.succeed("mkdir /tmp/repo")
|
client.succeed("mkdir -p ~/.ssh")
|
||||||
client1.succeed("mkdir -p $HOME/.ssh")
|
client.succeed("(umask 0077; cat ${snakeOilPrivateKey} > ~/.ssh/privk)")
|
||||||
client1.succeed(f"cat {PRIVK} > $HOME/.ssh/privk")
|
|
||||||
client1.succeed("chmod 0400 $HOME/.ssh/privk")
|
client.succeed("mkdir /tmp/repo")
|
||||||
client1.succeed("git -C /tmp/repo init")
|
client.succeed("git -C /tmp/repo init")
|
||||||
client1.succeed("echo hello world > /tmp/repo/testfile")
|
client.succeed("echo 'hello world' > /tmp/repo/testfile")
|
||||||
client1.succeed("git -C /tmp/repo add .")
|
client.succeed("git -C /tmp/repo add .")
|
||||||
client1.succeed("git config --global user.email test@localhost")
|
client.succeed("git -C /tmp/repo commit -m 'Initial import'")
|
||||||
client1.succeed("git config --global user.name test")
|
client.succeed("git -C /tmp/repo remote add origin ${remoteUri}")
|
||||||
client1.succeed("git -C /tmp/repo commit -m 'Initial import'")
|
|
||||||
client1.succeed(f"git -C /tmp/repo remote add origin {REPO}")
|
|
||||||
|
|
||||||
server.wait_for_unit("forgejo.service")
|
server.wait_for_unit("forgejo.service")
|
||||||
server.wait_for_open_port(3000)
|
server.wait_for_open_port(3000)
|
||||||
|
@ -143,18 +148,14 @@ let
|
||||||
+ ' -d \'{"key":"${snakeOilPublicKey}","read_only":true,"title":"SSH"}\'''
|
+ ' -d \'{"key":"${snakeOilPublicKey}","read_only":true,"title":"SSH"}\'''
|
||||||
)
|
)
|
||||||
|
|
||||||
client1.succeed(
|
client.succeed("git -C /tmp/repo push origin main")
|
||||||
f"GIT_SSH_COMMAND='{GIT_SSH_COMMAND}' git -C /tmp/repo push origin master"
|
|
||||||
)
|
|
||||||
|
|
||||||
client2.succeed("mkdir -p $HOME/.ssh")
|
client.succeed("git clone ${remoteUri} /tmp/repo-clone")
|
||||||
client2.succeed(f"cat {PRIVK} > $HOME/.ssh/privk")
|
print(client.succeed("ls -lash /tmp/repo-clone"))
|
||||||
client2.succeed("chmod 0400 $HOME/.ssh/privk")
|
assert "hello world" == client.succeed("cat /tmp/repo-clone/testfile").strip()
|
||||||
client2.succeed(f"GIT_SSH_COMMAND='{GIT_SSH_COMMAND}' git clone {REPO}")
|
|
||||||
client2.succeed('test "$(cat repo/testfile | xargs echo -n)" = "hello world"')
|
|
||||||
|
|
||||||
with subtest("Testing git protocol version=2 over ssh"):
|
with subtest("Testing git protocol version=2 over ssh"):
|
||||||
git_protocol = client2.succeed(f"GIT_SSH_COMMAND='{GIT_SSH_COMMAND}' GIT_TRACE2_EVENT=true git -C repo fetch |& grep negotiated-version")
|
git_protocol = client.succeed("GIT_TRACE2_EVENT=true git -C /tmp/repo-clone fetch |& grep negotiated-version")
|
||||||
version = json.loads(git_protocol).get("value")
|
version = json.loads(git_protocol).get("value")
|
||||||
assert version == "2", f"git did not negotiate protocol version 2, but version {version} instead."
|
assert version == "2", f"git did not negotiate protocol version 2, but version {version} instead."
|
||||||
|
|
||||||
|
@ -181,4 +182,4 @@ let
|
||||||
});
|
});
|
||||||
in
|
in
|
||||||
|
|
||||||
listToAttrs (map makeGForgejoTest supportedDbTypes)
|
listToAttrs (map makeForgejoTest supportedDbTypes)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user