on eac@config-deploy-module help sign in
obelisk/all-tests.nix
145 lines 5.9 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()
66 githost.wait_for_open_port("22")
68 with subtest("test obelisk is installed"):
69 client.succeed("ob --help")
71 with subtest("test the client can access the server via ssh"):
72 client.succeed("mkdir -p ~/.ssh/")
73 client.succeed(
74 "cp ${privateKeyFile} ~/.ssh/id_rsa"
75 )
76 client.succeed("chmod 600 ~/.ssh/id_rsa")
77 client.wait_until_succeeds(
78 "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa githost true"
79 )
80 client.succeed(
81 "cp ${sshConfigFile} ~/.ssh/config"
82 )
83 client.wait_until_succeeds("ssh githost true")
85 with subtest("test a remote bare repo can be started"):
86 githost.succeed("mkdir -p ~/myorg/myapp.git")
87 githost.succeed("cd ~/myorg/myapp.git && git init --bare")
89 with subtest("test a git project can be configured with a remote using ssh"):
90 client.succeed("mkdir -p ~/code/myapp")
91 client.succeed("cd ~/code/myapp && git init")
92 client.succeed(
93 "cp ${thunkableSample} ~/code/myapp/default.nix"
94 )
95 client.succeed("cd ~/code/myapp && git add .")
96 client.succeed('git config --global user.email "you@example.com"')
97 client.succeed('git config --global user.name "Your Name"')
98 client.succeed('cd ~/code/myapp && git commit -m "Initial"')
99 client.succeed(
100 "cd ~/code/myapp && git remote add origin root@githost:/root/myorg/myapp.git"
101 )
104 with subtest("test pushing code to the remote"):
105 client.succeed("cd ~/code/myapp && git push -u origin master")
106 client.succeed("cd ~/code/myapp && git status")
108 with subtest("test obelisk can pack"):
109 client.succeed("ob -v thunk pack ~/code/myapp")
110 client.succeed("grep -qF 'git' ~/code/myapp/default.nix")
111 client.succeed("grep -qF 'myorg' ~/code/myapp/git.json")
112 client.succeed("ob -v thunk unpack ~/code/myapp")
114 with subtest("test obelisk can set the public / private flag"):
115 client.succeed("ob -v thunk pack ~/code/myapp --private")
116 client.fail("""grep -qF '"private": practice' ~/code/myapp/git.json""")
117 client.succeed("""grep -qF '"private": true' ~/code/myapp/git.json""")
118 client.succeed("nix-build ~/code/myapp")
119 client.succeed("ob -v thunk unpack ~/code/myapp")
120 client.succeed("ob -v thunk pack ~/code/myapp --public")
121 client.succeed("""grep -qF '"private": false' ~/code/myapp/git.json""")
122 client.succeed("nix-build ~/code/myapp")
123 client.succeed("ob -v thunk unpack ~/code/myapp")
125 with subtest("test building an invalid thunk fails"):
126 client.succeed("cd ~/code/myapp && git checkout -b bad")
127 client.succeed(
128 "cp ${invalidThunkableSample} ~/code/myapp/default.nix"
129 )
130 client.succeed("cd ~/code/myapp && git add .")
131 client.succeed('git config --global user.email "you@example.com"')
132 client.succeed('git config --global user.name "Your Name"')
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("test 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 }) {}