on ae@obeliskenvs-tabulation help sign in
obelisk/all-tests.nix
145 lines 5.7 kB history raw
1{
2 supportedSystems ? [ builtins.currentSystem ]
3}:
4let
5 nginxRoot = "/run/nginx";
6 obelisk = import ./default.nix {};
7 # Get NixOS a pre-release 20.03 that contains the python based tests and recursive nix
8 pkgs = import (builtins.fetchTarball https://github.com/nixos/nixpkgs/archive/3de5266.tar.gz) {};
9 sshKeys = import (pkgs.path + /nixos/tests/ssh-keys.nix) pkgs;
10 make-test = import (pkgs.path + /nixos/tests/make-test-python.nix);
11 obelisk-everywhere = (import ./all-builds.nix { inherit supportedSystems; }).x86_64-linux.cache;
12 snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
13 snakeOilPublicKey = sshKeys.snakeOilPublicKey;
14in
15 make-test ({...}: {
16 name = "obelisk";
17 nodes = {
18 githost = {
19 networking.firewall.allowedTCPPorts = [ 22 80 ];
20 services.openssh = {
21 enable = true;
22 };
23 environment.systemPackages = [
24 pkgs.git
25 ];
26 users.users.root.openssh.authorizedKeys.keys = [
27 snakeOilPublicKey
28 ];
29 };
31 client = {
32 imports = [
33 (pkgs.path + /nixos/modules/installer/cd-dvd/channel.nix)
34 ];
35 nix.useSandbox = false;
36 nix.binaryCaches = [];
37 environment.systemPackages = [
38 obelisk.command
39 obelisk.shell
40 obelisk-everywhere
41 pkgs.git
42 ];
43 };
44 };
46 testScript =
47 let
48 privateKeyFile = pkgs.writeText "id_rsa" ''${snakeOilPrivateKey}'';
49 thunkableSample = pkgs.writeText "default.nix" ''
50 let pkgs = import <nixpkgs> {}; in pkgs.git
51 '';
52 invalidThunkableSample = pkgs.writeText "default.nix" ''
53 let pkgs = import <nixpkgs> {}; in pkgtypo.git
54 '';
55 sshConfigFile = pkgs.writeText "ssh_config" ''
56 Host *
57 StrictHostKeyChecking no
58 UserKnownHostsFile=/dev/null
59 ConnectionAttempts=1
60 ConnectTimeout=1
61 IdentityFile=~/.ssh/id_rsa
62 User=root
63 '';
64 in ''
65 start_all()
67 with subtest("obelisk is installed and git is configured"):
68 client.succeed("ob --help")
69 client.succeed('git config --global user.email "you@example.com"')
70 client.succeed('git config --global user.name "Your Name"')
72 githost.wait_for_open_port("22")
74 with subtest("the client can access the server via ssh"):
75 client.succeed("mkdir -p ~/.ssh/")
76 client.succeed(
77 "cp ${privateKeyFile} ~/.ssh/id_rsa"
78 )
79 client.succeed("chmod 600 ~/.ssh/id_rsa")
80 client.wait_until_succeeds(
81 "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa githost true"
82 )
83 client.succeed(
84 "cp ${sshConfigFile} ~/.ssh/config"
85 )
86 client.wait_until_succeeds("ssh githost true")
88 with subtest("a remote bare repo can be started"):
89 githost.succeed("mkdir -p ~/myorg/myapp.git")
90 githost.succeed("cd ~/myorg/myapp.git && git init --bare")
92 with subtest("a git project can be configured with a remote using ssh"):
93 client.succeed("mkdir -p ~/code/myapp")
94 client.succeed("cd ~/code/myapp && git init")
95 client.succeed(
96 "cp ${thunkableSample} ~/code/myapp/default.nix"
97 )
98 client.succeed("cd ~/code/myapp && git add .")
100 client.succeed('cd ~/code/myapp && git commit -m "Initial"')
101 client.succeed(
102 "cd ~/code/myapp && git remote add origin root@githost:/root/myorg/myapp.git"
103 )
106 with subtest("pushing code to the remote"):
107 client.succeed("cd ~/code/myapp && git push -u origin master")
108 client.succeed("cd ~/code/myapp && git status")
110 with subtest("obelisk can pack"):
111 client.succeed("ob -v thunk pack ~/code/myapp")
112 client.succeed("grep -qF 'git.json' ~/code/myapp/thunk.nix")
113 client.succeed("grep -qF 'myorg' ~/code/myapp/git.json")
114 client.succeed("ob -v thunk unpack ~/code/myapp")
116 with subtest("obelisk can set the public / private flag"):
117 client.succeed("ob -v thunk pack ~/code/myapp --private")
118 client.fail("""grep -qF '"private": practice' ~/code/myapp/git.json""")
119 client.succeed("""grep -qF '"private": true' ~/code/myapp/git.json""")
120 client.succeed("nix-build ~/code/myapp")
121 client.succeed("ob -v thunk unpack ~/code/myapp")
122 client.succeed("ob -v thunk pack ~/code/myapp --public")
123 client.succeed("""grep -qF '"private": false' ~/code/myapp/git.json""")
124 client.succeed("nix-build ~/code/myapp")
125 client.succeed("ob -v thunk unpack ~/code/myapp")
127 with subtest("building an invalid thunk fails"):
128 client.succeed("cd ~/code/myapp && git checkout -b bad")
129 client.succeed(
130 "cp ${invalidThunkableSample} ~/code/myapp/default.nix"
131 )
132 client.succeed("cd ~/code/myapp && git add .")
133 client.succeed('cd ~/code/myapp && git commit -m "Bad commit"')
134 client.succeed("cd ~/code/myapp && git push -u origin bad")
135 client.succeed("ob -v thunk pack ~/code/myapp --public")
136 client.fail("nix-build ~/code/myapp")
137 client.succeed("ob -v thunk unpack ~/code/myapp")
138 client.succeed("cd ~/code/myapp && git checkout master")
140 with subtest("obelisk can detect private repos"):
141 client.succeed("ob -v thunk pack ~/code/myapp")
142 client.succeed("""grep -qF '"private": true' ~/code/myapp/git.json""")
143 client.succeed("ob -v thunk unpack ~/code/myapp")
144 '';
145 }) {}