Skip to content

Commit 05ffaad

Browse files
committed
Added tests
1 parent aa30d33 commit 05ffaad

File tree

5 files changed

+130
-5
lines changed

5 files changed

+130
-5
lines changed

flake.lock

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

flake.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
pyproject-nix.url = "github:nix-community/pyproject.nix";
1212
pyproject-nix.inputs.nixpkgs.follows = "nixpkgs";
1313

14+
treefmt-nix.url = "github:numtide/treefmt-nix";
15+
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
16+
1417
uv2nix.url = "github:adisbladis/uv2nix";
1518
uv2nix.inputs.pyproject-nix.follows = "pyproject-nix";
1619
uv2nix.inputs.nixpkgs.follows = "nixpkgs";
@@ -26,6 +29,6 @@
2629
inputs:
2730
inputs.blueprint {
2831
inherit inputs;
29-
prefix = "nix";
32+
prefix = "nix/";
3033
};
3134
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{ flake, pkgs, ... }:
2+
let
3+
inherit (pkgs) lib;
4+
5+
secrets = pkgs.writeText "strykeforce-test-secrets" ''
6+
SECRET_KEY="not-a-secret"
7+
TBA_READ_KEY=
8+
SENTRY_DSN=
9+
EMAIL_HOST_USER=
10+
EMAIL_HOST_PASSWORD=
11+
'';
12+
in
13+
pkgs.nixosTest {
14+
name = "strykeforce-nixos-test";
15+
meta.platforms = lib.platforms.linux;
16+
17+
nodes.machine =
18+
{ ... }:
19+
{
20+
imports = [
21+
flake.nixosModules.default
22+
];
23+
24+
strykeforce.services.website = {
25+
enable = true;
26+
allowedHosts = "localhost";
27+
ssl = false;
28+
secrets = [ secrets ];
29+
};
30+
31+
services.postgresql = {
32+
enable = true;
33+
package = pkgs.postgresql_16;
34+
ensureDatabases = [ "strykeforce" ];
35+
ensureUsers = [
36+
{
37+
name = "strykeforce";
38+
ensureDBOwnership = true;
39+
}
40+
];
41+
};
42+
43+
system.stateVersion = "24.11";
44+
};
45+
46+
testScript =
47+
{ nodes, ... }:
48+
''
49+
# wait for service
50+
machine.wait_for_unit("strykeforce-website.service")
51+
machine.wait_until_succeeds("curl -sLf http://localhost:8000/static/2767/main.css")
52+
machine.succeed("curl -sLf http://localhost:8000/static/2767/main.js")
53+
html = machine.succeed("curl -sLf http://localhost:8000/admin/")
54+
assert "<title>Sign in - Wagtail</title>" in html
55+
'';
56+
}

nix/formatter.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{ inputs, pkgs, ... }:
2+
inputs.treefmt-nix.lib.mkWrapper pkgs {
3+
projectRootFile = "flake.nix";
4+
programs.fish_indent.enable = true;
5+
6+
programs.mdformat.enable = true;
7+
programs.mdformat.settings.number = true;
8+
9+
programs.nixfmt.enable = true;
10+
programs.stylua.enable = true;
11+
programs.yamlfmt.enable = true;
12+
13+
settings = {
14+
global.excludes = [ "*.{age,gif,png,svg,env,envrc,gitignore,tmTheme,sublime-syntax,theme}" ];
15+
};
16+
}

nix/packages/venv.nix

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
1-
{ flake, pkgs, ... }:
1+
{
2+
flake,
3+
pkgs,
4+
perSystem,
5+
...
6+
}:
27
let
38
pythonSet = flake.lib.pythonSets pkgs;
49
workspace = flake.lib.workspace;
510
in
611
pythonSet.mkVirtualEnv "styrkeforce-env" workspace.deps.default
12+
// {
13+
passthru.tests = {
14+
unit-tests =
15+
let
16+
inherit (perSystem.self) venv;
17+
in
18+
pkgs.stdenvNoCC.mkDerivation {
19+
name = "strykeforce-unittest";
20+
src = ../../.;
21+
nativeBuildInputs = [ venv ];
22+
dontConfigure = true;
23+
dontInstall = true;
24+
25+
buildPhase = ''
26+
runHook preBuild
27+
export DJANGO_SETTINGS_MODULE="website.settings.test"
28+
export TBA_READ_KEY=
29+
30+
${venv}/bin/python ./website/manage.py test website.events.tests > $out 2>&1
31+
runHook postBuild
32+
'';
33+
};
34+
};
35+
}

0 commit comments

Comments
 (0)