about summary refs log tree commit diff
path: root/nixos/tests/evcc.nix
blob: b445735ede98a51d1c51f3d58b081600f5b1c611 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import ./make-test-python.nix ({ pkgs, lib, ...} :

{
  name = "evcc";
  meta.maintainers = with lib.maintainers; [ hexa ];

  nodes = {
    machine = { config, ... }: {
      services.evcc = {
        enable = true;
        settings = {
          network = {
            schema = "http";
            host = "localhost";
            port = 7070;
          };

          log = "info";

          site = {
            title = "NixOS Test";
            meters = {
              grid = "grid";
              pv = "pv";
            };
          };

          meters = [ {
            type = "custom";
            name = "grid";
            power = {
              source = "script";
              cmd = "/bin/sh -c 'echo -4500'";
            };
          } {
            type = "custom";
            name = "pv";
            power = {
              source = "script";
              cmd = "/bin/sh -c 'echo 7500'";
            };
          } ];

          chargers = [ {
            name = "dummy-charger";
            type = "custom";
            status = {
              source = "script";
              cmd = "/bin/sh -c 'echo charger status F'";
            };
            enabled = {
              source = "script";
              cmd = "/bin/sh -c 'echo charger enabled state false'";
            };
            enable = {
              source = "script";
              cmd = "/bin/sh -c 'echo set charger enabled state true'";
            };
            maxcurrent = {
              source = "script";
              cmd = "/bin/sh -c 'echo set charger max current 7200'";
            };
          } ];

          loadpoints = [ {
            title = "Dummy";
            charger = "dummy-charger";
          } ];
        };
      };
    };
  };

  testScript = ''
    start_all()

    machine.wait_for_unit("evcc.service")
    machine.wait_for_open_port(7070)

    with subtest("Check package version propagates into frontend"):
        machine.fail(
            "curl --fail http://localhost:7070 | grep '0.0.1-alpha'"
        )
        machine.succeed(
            "curl --fail http://localhost:7070 | grep '${pkgs.evcc.version}'"
        )

    with subtest("Check journal for errors"):
        _, output = machine.execute("journalctl -o cat -u evcc.service")
        assert "FATAL" not in output

    with subtest("Check systemd hardening"):
        _, output = machine.execute("systemd-analyze security evcc.service | grep -v '✓'")
        machine.log(output)
  '';
})