diff --git a/Makefile b/Makefile index 2e166433..a60279b8 100644 --- a/Makefile +++ b/Makefile @@ -88,11 +88,11 @@ release: CLIENT_VM := abra-client vm-client-status: sudo systemctl status microvm@$(CLIENT_VM).service -vm-client-create: +vm-client-create:test-integration-hosts sudo microvm -f git+file://$$(pwd) -c $(CLIENT_VM) vm-client-start: sudo systemctl start microvm@$(CLIENT_VM).service -vm-client-update: +vm-client-update:test-integration-hosts sudo microvm -R -f git+file://$$(pwd) -u $(CLIENT_VM) vm-client-run: sudo microvm -f git+file://$$(pwd) -r $(CLIENT_VM) @@ -121,6 +121,8 @@ vm-server-delete: vm-server-stop vm-server-connect: ssh abra@10.0.0.3 -i ./tests/resources/local_integration_ssh +test-integration-hosts: + ./scripts/tests/extra_hosts test-integration: ssh-add ./tests/resources/local_integration_ssh @bats -Tp tests/integration --verbose-run diff --git a/flake.nix b/flake.nix index 9385e2e6..f9127896 100644 --- a/flake.nix +++ b/flake.nix @@ -27,7 +27,8 @@ pkgs = nixpkgs.legacyPackages.${system}; publicKey = builtins.readFile ./tests/resources/local_integration_ssh.pub; privateKey = builtins.readFile ./tests/resources/local_integration_ssh; - localDomainHosts = builtins.readFile ./tests/resources/local_hosts; + # local DNS aliases for the server host + extraHosts = builtins.readFile ./tests/resources/extra_hosts; username = "abra"; password = "abra"; defaultDNS = [ @@ -54,7 +55,7 @@ username password defaultDNS - localDomainHosts + extraHosts ; }; }; @@ -71,7 +72,6 @@ username password defaultDNS - localDomainHosts ; }; }; diff --git a/nix/hosts/client/configuration.nix b/nix/hosts/client/configuration.nix index 3b903994..037b0686 100644 --- a/nix/hosts/client/configuration.nix +++ b/nix/hosts/client/configuration.nix @@ -5,7 +5,7 @@ privateKey, username, defaultDNS, - localDomainHosts, + extraHosts, ... }: let @@ -94,7 +94,7 @@ in networking.firewall.allowedTCPPorts = [ 22 ]; networking.firewall.allowedUDPPorts = [ 22 ]; - networking.extraHosts = localDomainHosts; + networking.extraHosts = extraHosts; environment.variables = { CGO_ENABLED = 0; diff --git a/scripts/tests/extra_hosts b/scripts/tests/extra_hosts new file mode 100755 index 00000000..0900674a --- /dev/null +++ b/scripts/tests/extra_hosts @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# This file generates local DNS aliases for the client VM for integration testing + +echo "generating hosts file..." +hosts_file_path="./tests/resources/extra_hosts" +echo "removing old file..." +rm -f $hosts_file_path + +# the server domain +server_ip="10.0.0.3" +domain="abra.local" +echo "$server_ip $domain" >> $hosts_file_path +# static subdomains used in integration tests +subdomains=("gitea" "zammad" "custom-html" "foo" "foobar") + +for subdomain in "${subdomains[@]}" +do + echo "$server_ip $subdomain.$domain" >> $hosts_file_path +done + +search_dir=./tests/integration +for entry in "$search_dir"/*.bats +do + file_name=$(basename "${entry}") + # converting file names to testing subdomains + subdomain=$(echo "$file_name" | tr . _) + echo "$server_ip $subdomain.$domain" >> $hosts_file_path +done + +echo "writing extra hosts success" diff --git a/tests/integration/helpers/hosts.bash b/tests/integration/helpers/hosts.bash deleted file mode 100755 index 39a395ff..00000000 --- a/tests/integration/helpers/hosts.bash +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -echo "generating hosts file..." - -hosts_file_path="./tests/resources/local_hosts" - -echo "removing old file..." -rm $hosts_file_path - -# default entries -# the server -echo "10.0.0.3 abra.local" >> $hosts_file_path -# used to spin up traefik -echo "10.0.0.3 traefik.abra.local" >> $hosts_file_path -# used in integration tests -echo "10.0.0.3 gitea.abra.local" >> $hosts_file_path -echo "10.0.0.3 zammad.abra.local" >> $hosts_file_path -echo "10.0.0.3 custom-html.abra.local" >> $hosts_file_path -echo "10.0.0.3 foo.abra.local" >> $hosts_file_path -echo "10.0.0.3 foobar.abra.local" >> $hosts_file_path - -search_dir=./tests/integration -for entry in "$search_dir"/*.bats -do - base_name=$(basename "${entry}") - # converting file names to testing subdomains - subdomain=$(echo "$base_name" | tr . _) - echo "10.0.0.3 $subdomain.abra.local" >> $hosts_file_path -done - -echo "writing hosts success" diff --git a/tests/resources/local_hosts b/tests/resources/extra_hosts similarity index 98% rename from tests/resources/local_hosts rename to tests/resources/extra_hosts index c7575f89..3df669c1 100644 --- a/tests/resources/local_hosts +++ b/tests/resources/extra_hosts @@ -1,5 +1,4 @@ 10.0.0.3 abra.local -10.0.0.3 traefik.abra.local 10.0.0.3 gitea.abra.local 10.0.0.3 zammad.abra.local 10.0.0.3 custom-html.abra.local