@@ -0,0 +1,99 @@
1+let
2+ nginxRoot = "/run/nginx";
3+ obelisk = import ./default.nix {};
4+ # Get NixOS a pre-release 20.03 that contains the python based tests and recursive nix
5+ pkgs = import (builtins.fetchTarball https://github.com/nixos/nixpkgs/archive/3de5266.tar.gz) {};
6+ sshKeys = import (pkgs.path + /nixos/tests/ssh-keys.nix) pkgs;
7+ make-test = import (pkgs.path + /nixos/tests/make-test-python.nix);
8+ obelisk-everything = (import ./release.nix {}).metaCache.x86_64-linux;
9+ snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
10+ snakeOilPublicKey = sshKeys.snakeOilPublicKey;
11+in
12+ make-test ({...}: {
13+ name = "obelisk";
14+ nodes = {
15+ githost = {
16+ networking.firewall.allowedTCPPorts = [ 22 80 ];
17+ services.openssh = {
18+ enable = true;
19+ };
20+ environment.systemPackages = [
21+ pkgs.git
22+ ];
23+ users.users.root.openssh.authorizedKeys.keys = [
24+ snakeOilPublicKey
25+ ];
26+ };
27+
28+ client = {
29+ imports = [
30+ (pkgs.path + /nixos/modules/installer/cd-dvd/channel.nix)
31+ ];
32+ nix.useSandbox = false;
33+ nix.binaryCaches = [];
34+ environment.systemPackages = [
35+ obelisk.command
36+ obelisk.shell
37+ pkgs.git
38+ ];
39+ };
40+ };
41+
42+ testScript =
43+ let
44+ privateKeyFile = pkgs.writeText "id_rsa" ''${snakeOilPrivateKey}'';
45+ sshConfigFile = pkgs.writeText "ssh_config" ''
46+ Host *
47+ StrictHostKeyChecking no
48+ UserKnownHostsFile=/dev/null
49+ ConnectionAttempts=1
50+ ConnectTimeout=1
51+ IdentityFile=~/.ssh/id_rsa
52+ User=root
53+ '';
54+ in ''
55+ githost.wait_for_open_port("22")
56+ with subtest("test the client can access the server via ssh"):
57+ start_all()
58+ client.succeed("mkdir -p ~/.ssh/")
59+ client.succeed(
60+ "cp ${privateKeyFile} ~/.ssh/id_rsa"
61+ )
62+ client.succeed("chmod 600 ~/.ssh/id_rsa")
63+ client.wait_until_succeeds(
64+ "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa githost true"
65+ )
66+ client.succeed(
67+ "cp ${sshConfigFile} ~/.ssh/config"
68+ )
69+ client.wait_until_succeeds("ssh githost true")
70+
71+ with subtest("test a remote bare repo can be started"):
72+ githost.succeed("mkdir -p ~/myorg/myapp.git")
73+ githost.succeed("cd ~/myorg/myapp.git && git init --bare")
74+
75+ with subtest("test a git project can be configured with a remote using ssh"):
76+ client.succeed("mkdir -p ~/code/myapp")
77+ client.succeed("cd ~/code/myapp && git init")
78+ client.succeed("cd ~/code/myapp && touch README")
79+ client.succeed("cd ~/code/myapp && git add .")
80+ client.succeed('git config --global user.email "you@example.com"')
81+ client.succeed('git config --global user.name "Your Name"')
82+ client.succeed('cd ~/code/myapp && git commit -m "Initial"')
83+ client.succeed(
84+ "cd ~/code/myapp && git remote add origin githost:/root/myorg/myapp.git"
85+ )
86+
87+ with subtest("test pushing code to the remote"):
88+ client.succeed("cd ~/code/myapp && git push -u origin master")
89+ client.succeed("cd ~/code/myapp && git status")
90+
91+ with subtest("test obelisk is installed"):
92+ client.succeed("ob --help")
93+ '';
94+ failingTests = ''
95+ # failure: Alert: obelisk currently only supports file, https, ssh, git protocols for plain Git remotes
96+ with subtest("test obelisk can pack"):
97+ client.succeed("ob thunk pack ~/code/myapp")
98+ '';
99+ })