Skip to content

Commit 1161630

Browse files
authored
merge: #3 from Rexcrazy804/tests-init
- the addition of tests came with the addition of flake inputs, you may `inputs.<x>.follows = ""` all the inputs, they are not needed for the module - TESTS!!!! Took me a while to get around to doing this but it wasn't hard at all. I am free from the nagging feeling that I might have not tested a change well enough :D - CI basically make github do some work for all the data they be sniffing
2 parents fc1ecda + fb86ceb commit 1161630

File tree

9 files changed

+197
-2
lines changed

9 files changed

+197
-2
lines changed

.github/workflows/test-module.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: "Hjem impure tests"
2+
on:
3+
push:
4+
branches: [ "master" ]
5+
paths: ['**.nix']
6+
pull_request:
7+
branches: [ "master" ]
8+
paths: ['**.nix']
9+
jobs:
10+
test-module:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: cachix/install-nix-action@v25
15+
with:
16+
nix_path: nixpkgs=channel:nixos-unstable
17+
- run: nix flake check -L

flake.lock

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
11
{
2-
outputs = {self, ...}: {
2+
# Realistically hjem-impure, the module, does not depend on any of these inputs.
3+
# However, untested software depreives me of sound sleep.
4+
# So for the sake of our common welfare,
5+
# we pull these flakes and run some tests
6+
7+
inputs = {
8+
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
9+
hjem.url = "github:feel-co/hjem";
10+
11+
hjem.inputs.nixpkgs.follows = "nixpkgs";
12+
hjem.inputs.smfh.follows = "";
13+
};
14+
15+
outputs = {
16+
self,
17+
nixpkgs,
18+
...
19+
} @ inputs: let
20+
inherit (nixpkgs.lib) getAttrs mapAttrs;
21+
pkgsFor = getAttrs ["x86_64-linux" "aarch64-linux"] nixpkgs.legacyPackages;
22+
eachSystem = fn: mapAttrs fn pkgsFor;
23+
in {
24+
checks = eachSystem (_: pkgs: {
25+
hjem-test = pkgs.callPackage ./nix/test {
26+
specialArgs = {inherit inputs self;};
27+
};
28+
});
29+
330
hjemModules = {
4-
hjem-impure = ./hjem-impure.nix;
31+
hjem-impure = ./nix/module.nix;
532
default = self.hjemModules.hjem-impure;
633
};
734
};
File renamed without changes.

nix/test/config.nix

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
inputs,
3+
self,
4+
...
5+
}: let
6+
dots = "${./dots}";
7+
in {
8+
imports = [inputs.hjem.nixosModules.default];
9+
system.stateVersion = "25.05";
10+
11+
users.users.kokomi = {
12+
isNormalUser = true;
13+
home = "/home/kokomi";
14+
};
15+
16+
hjem.extraModules = [self.hjemModules.default];
17+
hjem.users.kokomi = {
18+
enable = true;
19+
user = "kokomi";
20+
impure = {
21+
enable = true;
22+
dotsDir = dots;
23+
dotsDirImpure = "/home/kokomi/dots";
24+
};
25+
xdg.config.files = {
26+
# this file should be relinked to dots/booru.toml
27+
"booru/config.toml".source = dots + "/booru.toml";
28+
# this directory should be relinked to dots/foot
29+
"foot".source = dots + "/foot";
30+
# this file should be made mutable
31+
"kokomi/kokomi.lua".text = ''
32+
print("everywhere I go, I see her face.")
33+
'';
34+
# the symlink for this directory should be replaced with a normal directory
35+
"uwsm".source = ./dots/uwsm;
36+
};
37+
};
38+
}

nix/test/default.nix

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
testers,
3+
specialArgs,
4+
}:
5+
testers.runNixOSTest {
6+
name = "hjem-impure tests";
7+
node = {inherit specialArgs;};
8+
nodes.Dracaena_Somnolenta = import ./config.nix; # <><
9+
10+
testScript = /*python*/ ''
11+
# preliminary hjem stuff
12+
# https://github.com/feel-co/hjem/blob/main/tests/basic.nix
13+
machine.succeed("loginctl enable-linger kokomi")
14+
machine.wait_until_succeeds("systemctl --user --machine=kokomi@ is-active systemd-tmpfiles-setup.service")
15+
16+
# ensure hjem links
17+
machine.succeed("[ -L ~kokomi/.config/booru/config.toml ]")
18+
machine.succeed("[ -L ~kokomi/.config/kokomi/kokomi.lua ]")
19+
machine.succeed("[ -L ~kokomi/.config/uwsm ]")
20+
machine.succeed("[ -L ~kokomi/.config/foot ]")
21+
22+
# copy test dots
23+
machine.copy_from_host("${./dots}", "/home/kokomi/dots")
24+
25+
# run hjem-impure and verify files
26+
machine.succeed("su -- kokomi -c 'hjem-impure'")
27+
# ensure kokomi.lua is not a symlink and is a simple file
28+
machine.succeed("[ -f ~kokomi/.config/kokomi/kokomi.lua ] && [ ! -L ~kokomi/.config/kokomi/kokomi.lua ]")
29+
# ensure that booru/config.toml is a symlink to dots/booru.toml
30+
machine.succeed("[ $(realpath ~kokomi/.config/booru/config.toml) == ~kokomi/dots/booru.toml ]")
31+
# ensure that .config/uwsm is not a symlink but a plain directory
32+
machine.succeed("[ ! -L ~kokomi/.config/uwsm ] && [ -d ~kokomi/.config/uwsm ]")
33+
# ensure that .config/foot is a symlink to dots/foot
34+
machine.succeed("[ $(realpath ~kokomi/.config/foot) == ~kokomi/dots/foot ]")
35+
# same thing as above but check one file deeper so that kokomi can be happy
36+
machine.succeed("[ $(realpath ~kokomi/.config/foot/foot.ini) == ~kokomi/dots/foot/foot.ini ]")
37+
38+
# my deslexic ass does not like the density of the comments above,
39+
# but my forgetfull ass will appreciate it later.
40+
'';
41+
}

nix/test/dots/booru.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# stripped example config from Rexcrazy804/booru.hs
2+
3+
[[sources]]
4+
provider = "danbooru"
5+
ids = ["5614777", "9590836"]
6+
7+
[filters]
8+
characters = { list = ["kokomi"], inverted = true }
9+
10+
[preview_filters]
11+
ratings = { list = ["g"], inverted = true }
12+
13+
[synonyms.characters]
14+
"kokomi" = ["sangonomiya_kokomi", "sangonomiya kokomi"]
15+
[synonyms.copyrights]
16+
"genshin" = ["genshin_impact", "yuanshen"]

nix/test/dots/foot/foot.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[main]
2+
gamma-correct-blending=false
3+
dpi-aware=yes
4+
initial-window-mode=maximized
5+
pad=5x5 center

nix/test/dots/uwsm/env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export XCURSOR_THEME=Kokomi_Cursor
2+
export XCURSOR_SIZE=24

0 commit comments

Comments
 (0)