From 3ae107376842cf75ecd4c0dac30ffce9bc7dbe2b Mon Sep 17 00:00:00 2001 From: Marco Vermeulen Date: Thu, 5 Dec 2013 13:51:49 +0000 Subject: [PATCH] Do not go offline when curl times out on initialisation. --- src/main/bash/gvm-init.sh | 10 +++++----- src/test/groovy/gvm/BootstrapSpec.groovy | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main/bash/gvm-init.sh b/src/main/bash/gvm-init.sh index 54713085..90a680e4 100644 --- a/src/main/bash/gvm-init.sh +++ b/src/main/bash/gvm-init.sh @@ -51,17 +51,17 @@ function gvm_set_candidates { } function gvm_check_offline { - RESPONSE="$1" - DETECT_HTML="$(echo "$RESPONSE" | tr '[:upper:]' '[:lower:]' | grep 'html')" - if [[ -z "$RESPONSE" || -n "$DETECT_HTML" ]]; then + GVM_RESPONSE="$1" + GVM_DETECT_HTML="$(echo "$GVM_RESPONSE" | tr '[:upper:]' '[:lower:]' | grep 'html')" + if [[ -n "$GVM_DETECT_HTML" ]]; then echo "GVM can't reach the internet so going offline. Re-enable online with:" echo "" echo " $ gvm offline disable" echo "" GVM_FORCE_OFFLINE="true" fi - unset RESPONSE - unset DETECT_HTML + unset GVM_RESPONSE + unset GVM_DETECT_HTML } # force zsh to behave well diff --git a/src/test/groovy/gvm/BootstrapSpec.groovy b/src/test/groovy/gvm/BootstrapSpec.groovy index 8486addc..941440b1 100644 --- a/src/test/groovy/gvm/BootstrapSpec.groovy +++ b/src/test/groovy/gvm/BootstrapSpec.groovy @@ -140,7 +140,7 @@ class BootstrapSpec extends Specification { bash = GvmBashEnvBuilder .create(gvmBaseDir) .withCurlStub(curlStub) - .withVersionToken("x.y.z") + .withVersionToken(gvmVersion) .withConfiguration("gvm_auto_selfupdate", "true") .build() bash.start() @@ -151,7 +151,25 @@ class BootstrapSpec extends Specification { then: ! bash.output.contains("A new version of GVM is available...") versionFile.text.contains(gvmVersion) + } + void "should not go offline if curl times out"(){ + given: 'a working gvm installation with api down' + def gvmVersion = "x.y.z" + def versionFile = new File(versionToken) + curlStub.primeWith("http://localhost:8080/app/version", "echo ''").build() + bash = GvmBashEnvBuilder + .create(gvmBaseDir) + .withCurlStub(curlStub) + .withConfiguration("gvm_auto_selfupdate", "true") + .build() + bash.start() + + when: 'bootstrap the system' + bash.execute("source $bootstrap") + + then: + ! bash.output.contains("GVM can't reach the internet so going offline.") } void "should ignore version if api returns garbage"(){