tests.basic -> tests.gotosocial
This commit is contained in:
parent
68e9b9a1e4
commit
1f466b63d3
9 changed files with 23 additions and 16 deletions
9
tests/gotosocial/configuration-package.nix
Normal file
9
tests/gotosocial/configuration-package.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
runCommand,
|
||||
}: runCommand "tests-basic-configuration-dot-nix" {
|
||||
} ''
|
||||
set -euo pipefail
|
||||
mkdir -vp "$out/share/nixos"
|
||||
cp -rv ${./configuration.nix} "$out/share/nixos/configuration.nix"
|
||||
#cp -rv ${../../modules/dynamicism} "$out/share/nixos/dynamicism"
|
||||
''
|
||||
71
tests/gotosocial/configuration.nix
Normal file
71
tests/gotosocial/configuration.nix
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
{ pkgs, lib, config, modulesPath, ... }:
|
||||
let
|
||||
name = config.networking.hostName;
|
||||
moduleList = import (modulesPath + "/module-list.nix");
|
||||
|
||||
dynixFromSearchPath = let
|
||||
res = builtins.tryEval <dynix>;
|
||||
in lib.optional res.success res.value;
|
||||
in
|
||||
{
|
||||
imports = moduleList ++ [
|
||||
"${modulesPath}/testing/test-instrumentation.nix"
|
||||
./hardware-configuration.nix
|
||||
] ++ lib.concatLists [
|
||||
dynixFromSearchPath
|
||||
];
|
||||
|
||||
system.switch.enable = true;
|
||||
documentation.enable = false;
|
||||
|
||||
networking.hostName = "machine";
|
||||
|
||||
boot.loader.grub = {
|
||||
enable = true;
|
||||
device = "/dev/vda";
|
||||
forceInstall = true;
|
||||
};
|
||||
|
||||
nix = {
|
||||
package = pkgs.lixPackageSets.latest.lix;
|
||||
nixPath = [
|
||||
"nixpkgs=${pkgs.path}"
|
||||
"/nix/var/nix/profiles/per-user/root/profile/share/nixos/modules"
|
||||
];
|
||||
|
||||
settings = {
|
||||
experimental-features = [ "nix-command" "pipe-operator" ];
|
||||
substituters = lib.mkForce [ ];
|
||||
hashed-mirrors = null;
|
||||
connect-timeout = 1;
|
||||
# For my debugging purposes.
|
||||
show-trace = true;
|
||||
};
|
||||
};
|
||||
|
||||
services.gotosocial = {
|
||||
enable = true;
|
||||
setupPostgresqlDB = true;
|
||||
settings = {
|
||||
application-name = "gotosocial-for-${name}";
|
||||
host = "${name}.local";
|
||||
};
|
||||
};
|
||||
|
||||
dynamicism.for.gotosocial.enable = true;
|
||||
|
||||
environment.pathsToLink = [ "/share" ];
|
||||
environment.extraOutputsToInstall = [ "modules" ];
|
||||
environment.variables = {
|
||||
"NIXOS_CONFIG" = "/etc/nixos/configuration.nix";
|
||||
};
|
||||
|
||||
environment.shellAliases = {
|
||||
ls = "eza --long --header --group --group-directories-first --classify --binary";
|
||||
};
|
||||
environment.systemPackages = with pkgs; [
|
||||
eza
|
||||
fd
|
||||
ripgrep
|
||||
];
|
||||
}
|
||||
7
tests/gotosocial/default.nix
Normal file
7
tests/gotosocial/default.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* Convenience shortcut for running this test from the command-line.
|
||||
* Normally this test is initialized from /tests/default.nix.
|
||||
*/
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
}: pkgs.testers.runNixOSTest ./test.nix
|
||||
7
tests/gotosocial/hardware-configuration.nix
Normal file
7
tests/gotosocial/hardware-configuration.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/** Dummy hardware configuration.
|
||||
* Will be replaced with the real one in the test VM.
|
||||
*/
|
||||
{ ... }:
|
||||
{
|
||||
|
||||
}
|
||||
90
tests/gotosocial/test-script.py
Normal file
90
tests/gotosocial/test-script.py
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
from pathlib import Path
|
||||
import shlex
|
||||
import textwrap
|
||||
from typing import cast, TYPE_CHECKING
|
||||
|
||||
from beartype import beartype
|
||||
|
||||
from test_driver.machine import Machine
|
||||
from test_driver.errors import RequestedAssertionFailed
|
||||
|
||||
if TYPE_CHECKING:
|
||||
global machine
|
||||
machine = cast(Machine, ...)
|
||||
assert machine.shell is not None
|
||||
|
||||
ls = "eza -lah --color=always --group-directories-first"
|
||||
|
||||
@beartype
|
||||
def run_log(machine: Machine, *commands: str, timeout: int | None = 60) -> str:
|
||||
output = ""
|
||||
for command in commands:
|
||||
with machine.nested(f"must succeed: {command}"):
|
||||
(status, out) = machine.execute(f"{command} | tee /dev/stderr", timeout=timeout)
|
||||
if status != 0:
|
||||
machine.log(f"output: {out}")
|
||||
raise RequestedAssertionFailed(
|
||||
f"command `{command}` failed (exit code {status})",
|
||||
)
|
||||
output += out
|
||||
|
||||
return output
|
||||
|
||||
@beartype
|
||||
def get_config_file() -> str:
|
||||
machine.wait_for_unit("gotosocial.service")
|
||||
gotosocial_pid = int(machine.get_unit_property("gotosocial.service", "MainPID"))
|
||||
print(f"{gotosocial_pid=}")
|
||||
|
||||
cmdline = machine.succeed(f"cat /proc/{gotosocial_pid}/cmdline")
|
||||
cmdline_args = cmdline.split("\0")
|
||||
|
||||
config_file_idx = cmdline_args.index("--config-path") + 1
|
||||
config_file = Path(cmdline_args[config_file_idx])
|
||||
|
||||
machine.log(f"copying from VM: {config_file=}")
|
||||
machine.copy_from_vm(config_file.as_posix())
|
||||
|
||||
config_file_path = machine.out_dir / config_file.name
|
||||
with open(config_file_path, "r") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
machine.wait_for_unit("default.target")
|
||||
assert "lix" in machine.succeed("nix --version").lower()
|
||||
machine.log("INIT")
|
||||
|
||||
machine.succeed("nix profile install -vv $(realpath /run/current-system/sw/share/nixos/modules/dynix)")
|
||||
|
||||
machine.succeed("nixos-generate-config")
|
||||
machine.succeed("mkdir -vp /etc/nixos")
|
||||
# Dereference is required since that configuration.nix is probably a symlink to the store.
|
||||
machine.succeed("cp -rv --dereference /run/current-system/sw/share/nixos/configuration.nix /etc/nixos/")
|
||||
|
||||
machine.log("REBUILDING configuration inside VM")
|
||||
machine.succeed("env PAGER= nixos-rebuild switch --log-format raw-with-logs --fallback")
|
||||
|
||||
config_text = get_config_file()
|
||||
lines = config_text.splitlines()
|
||||
application_name = next((line for line in lines if line.startswith("application-name:")), None)
|
||||
assert application_name is not None, f"no 'application-name:' found in config file: {textwrap.indent(config_text, "")}"
|
||||
assert "gotosocial-for-machine" in application_name, f"'gotosocial-for-machine' should be in {application_name=}"
|
||||
|
||||
new_app_name = "yay!"
|
||||
expr = textwrap.dedent(f"""
|
||||
let
|
||||
nixos = import <nixpkgs/nixos> {{ }};
|
||||
in nixos.config.dynamicism.doChange {{
|
||||
option = "services.gotosocial.settings.application-name";
|
||||
value = "{new_app_name}";
|
||||
}}
|
||||
""").strip()
|
||||
machine.succeed(rf"""
|
||||
nix run --show-trace --log-format raw-with-logs --impure -E {shlex.quote(expr)}
|
||||
""".strip())
|
||||
|
||||
config_file_new = get_config_file()
|
||||
lines = config_file_new.splitlines()
|
||||
|
||||
application_name = next(line for line in lines if line.startswith("application-name:"))
|
||||
assert new_app_name in application_name, f"'{new_app_name}' should be in {application_name=}"
|
||||
44
tests/gotosocial/test.nix
Normal file
44
tests/gotosocial/test.nix
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
{ dynix, ... }:
|
||||
|
||||
{
|
||||
name = "nixos-test-dynamicism-main";
|
||||
|
||||
defaults = { ... }: { };
|
||||
|
||||
extraPythonPackages = p: [
|
||||
p.beartype
|
||||
];
|
||||
|
||||
nodes.machine = { pkgs, config, ... }: {
|
||||
# NOTE: Anything in this `nodes.machine = ` module will not be included
|
||||
# in the VM's NixOS configuration once it does `nixos-rebuild switch`,
|
||||
# except for `./configuration.nix` which will be copied to `/etc/nixos/`.
|
||||
# dynix will also be statefully installed to root's user profile.
|
||||
imports = [
|
||||
./configuration.nix
|
||||
(toString dynix)
|
||||
];
|
||||
|
||||
system.includeBuildDependencies = true;
|
||||
system.switch.enable = true;
|
||||
|
||||
virtualisation.additionalPaths = [ config.system.build.toplevel ];
|
||||
virtualisation = {
|
||||
memorySize = 4096;
|
||||
cores = 4;
|
||||
writableStore = true;
|
||||
mountHostNixStore = true;
|
||||
installBootLoader = true;
|
||||
};
|
||||
|
||||
environment.systemPackages = let
|
||||
configFileTree = pkgs.callPackage ./configuration-package.nix { };
|
||||
in [
|
||||
configFileTree
|
||||
];
|
||||
};
|
||||
|
||||
# What's a little IFD between friends?
|
||||
testScript = ./test-script.py
|
||||
|> builtins.readFile;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue