From d90242029047942bd159242417f2fda03c795582 Mon Sep 17 00:00:00 2001 From: WilliButz Date: Thu, 27 Jun 2019 18:11:09 +0200 Subject: [PATCH] nixos/tests: add test for loki --- nixos/tests/all-tests.nix | 1 + nixos/tests/loki.nix | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 nixos/tests/loki.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 359f62751b9..2f527bfa090 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -139,6 +139,7 @@ in #lightdm = handleTest ./lightdm.nix {}; limesurvey = handleTest ./limesurvey.nix {}; login = handleTest ./login.nix {}; + loki = handleTest ./loki.nix {}; #logstash = handleTest ./logstash.nix {}; mailcatcher = handleTest ./mailcatcher.nix {}; mathics = handleTest ./mathics.nix {}; diff --git a/nixos/tests/loki.nix b/nixos/tests/loki.nix new file mode 100644 index 00000000000..9c3058d02f8 --- /dev/null +++ b/nixos/tests/loki.nix @@ -0,0 +1,37 @@ +import ./make-test.nix ({ lib, pkgs, ... }: + +{ + name = "loki"; + + meta = with lib.maintainers; { + maintainers = [ willibutz ]; + }; + + machine = { ... }: { + services.loki = { + enable = true; + configFile = "${pkgs.grafana-loki.src}/cmd/loki/loki-local-config.yaml"; + }; + systemd.services.promtail = { + description = "Promtail service for Loki test"; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + ExecStart = '' + ${pkgs.grafana-loki}/bin/promtail --config.file ${pkgs.grafana-loki.src}/cmd/promtail/promtail-local-config.yaml + ''; + DynamicUser = true; + }; + }; + }; + + testScript = '' + $machine->start; + $machine->waitForUnit("loki.service"); + $machine->waitForUnit("promtail.service"); + $machine->waitForOpenPort(3100); + $machine->waitForOpenPort(9080); + $machine->succeed("echo 'Loki Ingestion Test' > /var/log/testlog"); + $machine->waitUntilSucceeds("${pkgs.grafana-loki}/bin/logcli --addr='http://localhost:3100' query --no-labels '{job=\"varlogs\",filename=\"/var/log/testlog\"}' | grep -q 'Loki Ingestion Test'"); + ''; +})