Skip to content

Commit

Permalink
More tests (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany authored Jan 8, 2024
1 parent c0ad3eb commit c46aae3
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 3 deletions.
28 changes: 25 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,42 @@ on:
jobs:
validate:
runs-on: ubuntu-latest
outputs:
drvpath: ${{ steps.test-derivation.outputs.drvpath }}

steps:

- uses: actions/checkout@v3

- uses: cachix/install-nix-action@v22
with:
extra_nix_config: "system-features = nixos-test benchmark big-parallel kvm"
nix_path: nixpkgs=channel:nixos-23.05

- name: build
run: NIXPKGS_ALLOW_UNFREE=1 nix build --impure

- name: check flake
run: NIXPKGS_ALLOW_UNFREE=1 nix flake check --impure
- name: check flake (runs tests)
run: NIXPKGS_ALLOW_UNFREE=1 nix flake check --impure --log-format internal-json
timeout-minutes: 15

- name: get test derivation path
id: test-derivation
if: always()
run: |
drvpath=$(ls -d /nix/store/*-vm-test-run-kolide-launcher)
echo "drvpath=${drvpath}" >> "$GITHUB_OUTPUT"
- name: upload test screenshot
uses: actions/upload-artifact@v4
if: always()
with:
name: test-screenshot
path: ${{ steps.test-derivation.outputs.drvpath }}/test.png
retention-days: 1

- name: show flake output attributes
run: nix flake show
run: nix flake show --impure

- name: show flake metadata
run: nix flake metadata
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ echo -n 'your-enroll-secret-goes-here' | sudo tee /etc/kolide-k2/secret
```

Then start the `kolide-launcher.service` service.

### Running tests

[NixOS tests](https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests)
live in the [./tests](./tests) directory and are included via flake checks.
They are able to be run via the `nix flake check` command.
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
packages.x86_64-linux.default = self.packages.x86_64-linux.kolide-launcher;

nixosModules.kolide-launcher = import ./modules/kolide-launcher self;

checks.x86_64-linux.kolide-launcher = import ./tests/kolide-launcher.nix { flake = self; };
};
}
80 changes: 80 additions & 0 deletions tests/kolide-launcher.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{ flake }:

let
nixpkgs = builtins.fetchTarball {
url = "https://github.com/nixOS/nixpkgs/archive/23.05.tar.gz";
sha256 = "sha256:10wn0l08j9lgqcw8177nh2ljrnxdrpri7bp0g7nvrsn9rkawvlbf";
};
pkgs = import nixpkgs { config = {}; overlays = []; };
in

pkgs.nixosTest {
name = "kolide-launcher";

nodes.machine = { config, pkgs, ... }: {
imports = [
flake.nixosModules.kolide-launcher
];

users.users.alice = {
isNormalUser = true;
description = "Alice Test";
password = "alicetest";
uid = 1000;
};

services.xserver.enable = true;
services.xserver.displayManager = {
lightdm.enable = true;
autoLogin = {
enable = true;
user = "alice";
};
};
services.xserver.desktopManager.mate.enable = true;

# This just quiets some log spam we don't care about
hardware.pulseaudio.enable = true;

services.kolide-launcher.enable = true;
system.stateVersion = "23.05";
};

testScript = { nodes, ... }:
let
user = nodes.machine.users.users.alice;
in
''
machine.start()
# TODO: currently launcher will shut itself down if its secret file doesn't exist,
# so we don't get all the way through setup and launcher doesn't stay running.
# In the future, we'll want to validate setup and that the service is running.
with subtest("kolide-launcher service starts"):
machine.wait_for_unit("kolide-launcher.service")
machine.sleep(10)
machine.systemctl("stop kolide-launcher.service")
with subtest("launcher set up correctly"):
machine.wait_for_file("/var/lib/kolide-k2/k2device.kolide.com/debug.json")
with subtest("get a screenshot"):
machine.wait_for_unit("display-manager.service")
machine.wait_for_file("${user.home}/.Xauthority")
machine.succeed("xauth merge ${user.home}/.Xauthority")
machine.wait_until_succeeds("pgrep marco")
machine.wait_for_window("marco")
machine.wait_until_succeeds("pgrep mate-panel")
machine.wait_for_window("Top Panel")
machine.wait_for_window("Bottom Panel")
machine.wait_until_succeeds("pgrep caja")
machine.wait_for_window("Caja")
machine.sleep(20)
machine.screenshot("test.png")
machine.shutdown()
'';
}

0 comments on commit c46aae3

Please sign in to comment.