@@ -0,0 +1,107 @@
1+{
2+ supportedSystems ? [ builtins.currentSystem ]
3+}:
4+let
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;
14+in
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+ };
30+
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+ };
45+
46+ testScript =
47+ let
48+ privateKeyFile = pkgs.writeText "id_rsa" ''${snakeOilPrivateKey}'';
49+ sshConfigFile = pkgs.writeText "ssh_config" ''
50+ Host *
51+ StrictHostKeyChecking no
52+ UserKnownHostsFile=/dev/null
53+ ConnectionAttempts=1
54+ ConnectTimeout=1
55+ IdentityFile=~/.ssh/id_rsa
56+ User=root
57+ '';
58+ in ''
59+ start_all()
60+ githost.wait_for_open_port("22")
61+
62+ with subtest("test obelisk is installed"):
63+ client.succeed("ob --help")
64+
65+ with subtest("test the client can access the server via ssh"):
66+ client.succeed("mkdir -p ~/.ssh/")
67+ client.succeed(
68+ "cp ${privateKeyFile} ~/.ssh/id_rsa"
69+ )
70+ client.succeed("chmod 600 ~/.ssh/id_rsa")
71+ client.wait_until_succeeds(
72+ "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa githost true"
73+ )
74+ client.succeed(
75+ "cp ${sshConfigFile} ~/.ssh/config"
76+ )
77+ client.wait_until_succeeds("ssh githost true")
78+
79+ with subtest("test a remote bare repo can be started"):
80+ githost.succeed("mkdir -p ~/myorg/myapp.git")
81+ githost.succeed("cd ~/myorg/myapp.git && git init --bare")
82+
83+ with subtest("test a git project can be configured with a remote using ssh"):
84+ client.succeed("mkdir -p ~/code/myapp")
85+ client.succeed("cd ~/code/myapp && git init")
86+ client.succeed("cd ~/code/myapp && touch README")
87+ client.succeed("cd ~/code/myapp && git add .")
88+ client.succeed('git config --global user.email "you@example.com"')
89+ client.succeed('git config --global user.name "Your Name"')
90+ client.succeed('cd ~/code/myapp && git commit -m "Initial"')
91+ client.succeed(
92+ "cd ~/code/myapp && git remote add origin root@githost:/root/myorg/myapp.git"
93+ )
94+
95+ with subtest("test pushing code to the remote"):
96+ client.succeed("cd ~/code/myapp && git push -u origin master")
97+ client.succeed("cd ~/code/myapp && git status")
98+
99+ with subtest("test obelisk can pack"):
100+ client.succeed("ob thunk pack ~/code/myapp")
101+ client.succeed("grep -qF 'git' ~/code/myapp/default.nix")
102+ client.succeed("grep -qF 'myorg' ~/code/myapp/git.json")
103+
104+ with subtest("test obelisk can detect private repos"):
105+ client.succeed("""grep -qF '"private": false' ~/code/myapp/git.json""")
106+ '';
107+ }) {}