summaryrefslogtreecommitdiffstats
path: root/nixos/tests/esphome.nix
blob: 8a84213f971de6b2f0a946f9cdd63e13e2e1cce3 (plain)
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
{ pkgs, lib, ... }:

let
  testPort = 6052;
  unixSocket = "/run/esphome/esphome.sock";
in
{
  name = "esphome";
  meta.maintainers = with lib.maintainers; [ oddlama ];

  nodes = {
    esphomeTcp =
      { ... }:
      {
        services.esphome = {
          enable = true;
          port = testPort;
          address = "0.0.0.0";
          openFirewall = true;
        };
      };

    esphomeUnix =
      { ... }:
      {
        services.esphome = {
          enable = true;
          enableUnixSocket = true;
        };
      };
  };

  testScript = ''
    esphomeTcp.wait_for_unit("esphome.service")
    esphomeTcp.wait_for_open_port(${toString testPort})
    esphomeTcp.succeed("curl --fail http://localhost:${toString testPort}/")

    esphomeUnix.wait_for_unit("esphome.service")
    esphomeUnix.wait_for_file("${unixSocket}")
    esphomeUnix.succeed("curl --fail --unix-socket ${unixSocket} http://localhost/")
  '';
}