flake/tests: pass testProfile as a shared arg

This commit is contained in:
NotAShelf 2024-05-06 23:23:52 +03:00
parent c3c76afda4
commit aa62e904d6
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
3 changed files with 42 additions and 40 deletions

View file

@ -2,6 +2,7 @@
inputs, inputs,
nixosTest, nixosTest,
homeManagerModules, homeManagerModules,
testProfile,
... ...
}: }:
nixosTest { nixosTest {
@ -10,8 +11,8 @@ nixosTest {
nodes.machine = { nodes.machine = {
imports = [ imports = [
testProfile
inputs.home-manager.nixosModules.home-manager inputs.home-manager.nixosModules.home-manager
../profiles/minimal.nix
]; ];
config = { config = {
@ -28,39 +29,5 @@ nixosTest {
}; };
}; };
testScript = '' testScript = "";
import subprocess
machine.wait_for_unit("default.target")
def check_errs(process):
# Check for errors
print("Connecting to Neovim process")
# Capture stdout and stderr
stdout, stderr = process.communicate()
# Print captured stdout and stderr
if stdout:
print("Captured stdout:")
print(stdout.decode('utf-8'))
if stderr:
print("Captured stderr:")
print(stderr.decode('utf-8'))
def run_neovim_headless():
print("Running Neovim in headless mode.")
# Run Neovim in headless mode
nvim_process = subprocess.Popen(['nvim', '--headless'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
check_errs(nvim_process)
# Load configuration file
nvim_process.stdin.write(b':NonExistentCommand\n')
nvim_process.stdin.flush()
# run Neovim in headless mode
# and expect it to return sucessfully
machine.succeed(run_neovim_headless())
'';
} }

View file

@ -1,6 +1,7 @@
{ {
nixosTest, nixosTest,
nixosModules, nixosModules,
testProfile,
... ...
}: }:
nixosTest { nixosTest {
@ -8,8 +9,8 @@ nixosTest {
nodes.machine = { nodes.machine = {
imports = [ imports = [
testProfile
nixosModules.nvf nixosModules.nvf
../profiles/minimal.nix
]; ];
config = { config = {
@ -17,5 +18,39 @@ nixosTest {
}; };
}; };
testScript = ""; testScript = ''
import subprocess
machine.wait_for_unit("default.target")
def check_errs(process):
# Check for errors
print("Connecting to Neovim process")
# Capture stdout and stderr
stdout, stderr = process.communicate()
# Print captured stdout and stderr
if stdout:
print("Captured stdout:")
print(stdout.decode('utf-8'))
if stderr:
print("Captured stderr:")
print(stderr.decode('utf-8'))
def run_neovim_headless():
print("Running Neovim in headless mode.")
# Run Neovim in headless mode
nvim_process = subprocess.Popen(['nvim', '--headless'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
check_errs(nvim_process)
# Load configuration file
nvim_process.stdin.write(b':NonExistentCommand\n')
nvim_process.stdin.flush()
# run Neovim in headless mode
# and expect it to return sucessfully
machine.succeed(run_neovim_headless())
'';
} }

View file

@ -16,20 +16,20 @@
defaultInherits = { defaultInherits = {
inherit (config.flake) homeManagerModules nixosModules; inherit (config.flake) homeManagerModules nixosModules;
inherit inputs; inherit inputs;
testProfile = ./profiles/minimal.nix;
}; };
callPackage = callPackageWith (recursiveUpdate pkgs defaultInherits); callPackage = callPackageWith (recursiveUpdate pkgs defaultInherits);
in { in {
checks = packagesFromDirectoryRecursive { checks = packagesFromDirectoryRecursive {
inherit callPackage; inherit callPackage;
testProfile = ../profiles/minimal.nix;
directory = ./checks; directory = ./checks;
}; };
# expose checks as packages to be built # expose checks as packages to be built
packages = { packages = {
test-home-manager-module = self'.checks.homeManagerModule.driverInteractive; test-home-manager-module = self'.checks.homeManagerModule.driverInteractive;
test-nixos-module = self'.checks.nixosModule.driverInteractive; # test-nixos-module = self'.checks.nixosModule.driverInteractive;
}; };
}; };
} }