From 84a3fcadd06c35a91eb84a5739452c53be55d8ea Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Mon, 5 Mar 2018 23:00:50 +0100 Subject: [PATCH] ofborg: add basic test --- modules/services/ofborg/default.nix | 12 ++++++------ release.nix | 1 + tests/services-ofborg.nix | 30 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 tests/services-ofborg.nix diff --git a/modules/services/ofborg/default.nix b/modules/services/ofborg/default.nix index ff691e85..eedb625d 100644 --- a/modules/services/ofborg/default.nix +++ b/modules/services/ofborg/default.nix @@ -91,18 +91,18 @@ in # FIXME: create logfiles automatically if defined. system.activationScripts.preActivation.text = '' - mkdir -p "${user.home}" - touch "${cfg.logFile}" - chown ${toString user.uid}:${toString user.gid} "${user.home}" "${cfg.logFile}" + mkdir -p '${user.home}' + touch '${cfg.logFile}' + chown ${toString user.uid}:${toString user.gid} '${user.home}' '${cfg.logFile}' ''; system.activationScripts.postActivation.text = '' - if ! test -f "${cfg.configFile}"; then + if ! test -f '${cfg.configFile}'; then echo >&2 "warning: ofborg config \"${cfg.configFile}\" does not exist" fi - chmod 600 "${cfg.configFile}" - chown ${toString user.uid}:${toString user.gid} "${cfg.configFile}" + chmod 600 '${cfg.configFile}' + chown ${toString user.uid}:${toString user.gid} '${cfg.configFile}' ''; }; diff --git a/release.nix b/release.nix index 6d50d575..662b7d14 100644 --- a/release.nix +++ b/release.nix @@ -99,6 +99,7 @@ let tests.programs-zsh = makeTest ./tests/programs-zsh.nix; tests.services-activate-system = makeTest ./tests/services-activate-system.nix; tests.services-buildkite-agent = makeTest ./tests/services-buildkite-agent.nix; + tests.services-ofborg = makeTest ./tests/services-ofborg.nix; tests.services-skhd = makeTest ./tests/services-skhd.nix; tests.system-defaults-write = makeTest ./tests/system-defaults-write.nix; tests.system-keyboard-mapping = makeTest ./tests/system-keyboard-mapping.nix; diff --git a/tests/services-ofborg.nix b/tests/services-ofborg.nix new file mode 100644 index 00000000..fc7d9b50 --- /dev/null +++ b/tests/services-ofborg.nix @@ -0,0 +1,30 @@ +{ config, pkgs, ... }: + +let + ofborg = pkgs.runCommand "ofborg-0.0.0" {} "mkdir $out"; +in + +{ + services.ofborg.enable = true; + services.ofborg.package = ofborg; + + users.knownGroups = [ "ofborg" ]; + users.knownUsers = [ "ofborg" ]; + + test = '' + echo >&2 "checking ofborg service in /Library/LaunchDaemons" + grep "org.nixos.ofborg" ${config.out}/Library/LaunchDaemons/org.nixos.ofborg.plist + grep "ofborg" ${config.out}/Library/LaunchDaemons/org.nixos.ofborg.plist + + echo >&2 "checking for user in /activate" + grep "OfBorg service user" ${config.out}/activate + + echo >&2 "checking for logfile permissions in /activate" + grep "touch '/var/log/ofborg.log'" ${config.out}/activate + grep "chown .* '/var/log/ofborg.log'" ${config.out}/activate + + echo >&2 "checking config.json permissions in /activate" + grep "chmod 600 '/var/lib/ofborg/config.json'" ${config.out}/activate + grep "chown .* '/var/lib/ofborg/config.json'" ${config.out}/activate + ''; +}