summaryrefslogtreecommitdiffstats
path: root/tests/programs-mas.nix
blob: 678c2be82077554804f46d18293a18fa586315dd (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
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
{
  config,
  lib,
  pkgs,
  ...
}:

let
  mas =
    pkgs.runCommand "mas-0.0.0" { } ''
          mkdir -p $out/bin
          cat > $out/bin/mas <<'EOF'
      #!/usr/bin/env bash
      exit 0
      EOF
          chmod +x $out/bin/mas
    ''
    // {
      meta.mainProgram = "mas";
    };
in
{
  system.primaryUser = "primary-mas-user";

  programs.mas = {
    enable = true;
    user = "test-mas-user";
    package = mas;
    update = true;
    cleanup = true;
    packages = {
      "1Password for Safari" = 1569813296;
      Xcode = 497799835;
    };
  };

  homebrew.masApps = {
    "KeepFromHomebrew" = 424242;
  };

  test = ''
    echo "checking mas present in systemPackages" >&2
    test -x ${config.out}/sw/bin/mas

    echo "checking mas activation script uses requested user" >&2
    grep -- '--user=test-mas-user' ${config.out}/activate

    echo "checking mas desired ids are present" >&2
    grep 'desiredIds=(' ${config.out}/activate
    grep '1569813296' ${config.out}/activate
    grep '497799835' ${config.out}/activate

    echo "checking mas install loop exists" >&2
    grep 'mas install \"$appId\"' ${config.out}/activate

    echo "checking mas update is triggered" >&2
    grep 'mas update' ${config.out}/activate

    echo "checking mas parses installedApps from mas list" >&2
    grep 'declare -A installedApps' ${config.out}/activate
    grep 'installedApps\[' ${config.out}/activate

    echo "checking mas cleanup log and uninstall" >&2
    grep 'removing .* from App Store' ${config.out}/activate
    grep 'runAsUser .*/mas uninstall' ${config.out}/activate

    echo "checking homebrew.masApps ids are kept during cleanup" >&2
    grep 'homebrewIds=(' ${config.out}/activate
    grep '424242' ${config.out}/activate
  '';
}