From 0aa603de442d23ef3fede1b43b45b76d5ad17a47 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Thu, 19 Feb 2015 16:37:31 -0200 Subject: [PATCH] Refactor tests to not depend on /etc/hosts --- test/bin/curl | 7 ++++++- test/colab_test.sh | 6 +++--- test/ip_helper.sh | 10 ++++++++++ test/reverse_proxy_test.sh | 4 ++-- test/test_helper.sh | 15 +++------------ 5 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 test/ip_helper.sh diff --git a/test/bin/curl b/test/bin/curl index d81769d..8967727 100755 --- a/test/bin/curl +++ b/test/bin/curl @@ -5,10 +5,15 @@ set -e unset http_proxy unset https_proxy +. $(dirname $0)/../ip_helper.sh + /usr/bin/curl \ --silent \ --noproxy '*' \ --fail \ --insecure \ - --header 'Host: softwarepublico.dev' \ + --resolve softwarepublico.dev:80:$reverseproxy \ + --resolve softwarepublico.dev:443:$reverseproxy \ + --resolve listas.softwarepublico.dev:80:$reverseproxy \ + --resolve listas.softwarepublico.dev:443:$reverseproxy \ "$@" diff --git a/test/colab_test.sh b/test/colab_test.sh index adc0e82..57bbbe2 100644 --- a/test/colab_test.sh +++ b/test/colab_test.sh @@ -13,15 +13,15 @@ test_colab_running() { } test_colab_responds() { - assertTrue 'colab responds' "run_on integration $curl http://localhost:8001" + assertTrue 'colab responds' "run_on integration curl --header 'Host: softwarepublico.dev' http://localhost:8001" } test_nginx_responds() { - assertTrue 'nginx reponds' "run_on integration $curl http://localhost" + assertTrue 'nginx reponds' "run_on integration curl --header 'Host: softwarepublico.dev' http://localhost" } test_nginx_virtualhost() { - local title="$(./test/bin/curl http://$integration/dashboard | grep '' | sed -e 's/^\s*//')" + local title="$(curl --header 'Host: softwarepublico.dev' http://$integration/dashboard | grep '<title>' | sed -e 's/^\s*//')" assertEquals "<title>Home - Colab" "$title" } diff --git a/test/ip_helper.sh b/test/ip_helper.sh new file mode 100644 index 0000000..3687df5 --- /dev/null +++ b/test/ip_helper.sh @@ -0,0 +1,10 @@ +# make IP addresses avaliable at the environment so we can refer to hosts by +# name, e.g. +# +# curl http://$reverseproxy +# nmap -p 5423 $database +# +# Each node in the `peers:` entry in nodes.yaml will have its own variable +# +eval $(ruby -ryaml -e 'YAML.load_file("nodes.yaml").first[1]["peers"].each { |k,v| puts "#{k}=#{v}" }') + diff --git a/test/reverse_proxy_test.sh b/test/reverse_proxy_test.sh index 707e7df..bae2ba4 100644 --- a/test/reverse_proxy_test.sh +++ b/test/reverse_proxy_test.sh @@ -1,12 +1,12 @@ . $(dirname $0)/test_helper.sh test_redirect_http_to_https() { - local redirect="$(./test/bin/curl --head http://$reverseproxy/ | sed -e '/Location:/ !d; s/\r//')" + local redirect="$(curl --header 'Host: softwarepublico.dev' --head http://$reverseproxy/ | sed -e '/Location:/ !d; s/\r//')" assertEquals "Location: https://softwarepublico.dev/" "$redirect" } test_reverse_proxy_to_colab() { - local title="$(./test/bin/curl https://$reverseproxy/dashboard | grep '' | sed -e 's/^\s*//')" + local title="$(curl --header 'Host: softwarepublico.dev' https://$reverseproxy/dashboard | grep '<title>' | sed -e 's/^\s*//')" assertEquals "<title>Home - Colab" "$title" } diff --git a/test/test_helper.sh b/test/test_helper.sh index 7d26132..3908222 100644 --- a/test/test_helper.sh +++ b/test/test_helper.sh @@ -1,3 +1,5 @@ +export PATH="$(dirname $0)/bin:$PATH" + run_on() { local vm="$1" shift @@ -19,15 +21,4 @@ wait_for() { return 1 } - -curl=/vagrant/test/bin/curl - -# make IP addresses avaliable at the environment so we can refer to hosts by -# name, e.g. -# -# curl http://$reverseproxy -# nmap -p 5423 $database -# -# Each node in the `peers:` entry in nodes.yaml will have its own variable -# -eval $(ruby -ryaml -e 'YAML.load_file("nodes.yaml").first[1]["peers"].each { |k,v| puts "#{k}=#{v}" }') +. $(dirname $0)/ip_helper.sh -- libgit2 0.21.2