Do not go offline when curl times out on initialisation.

This commit is contained in:
Marco Vermeulen
2013-12-05 13:51:49 +00:00
parent d203d4807b
commit 3ae1073768
2 changed files with 24 additions and 6 deletions

View File

@@ -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

View File

@@ -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"(){