diff --git a/src/main/bash/gvm-init.sh b/src/main/bash/gvm-init.sh index cfdb405f..a416af48 100644 --- a/src/main/bash/gvm-init.sh +++ b/src/main/bash/gvm-init.sh @@ -186,7 +186,7 @@ if [ -f "${GVM_DIR}/etc/config" ]; then fi # test the configuration setting for suggestive selfupdate -if [[ "$gvm_suggestive_selfupdate" == "true" ]]; then +if [[ -z "$gvm_suggestive_selfupdate" || "$gvm_suggestive_selfupdate" == 'true' ]]; then # determine if up to date GVM_REMOTE_VERSION=$(curl -s "${GVM_SERVICE}/app/version" -m 1) @@ -202,7 +202,7 @@ if [[ "$gvm_suggestive_selfupdate" == "true" ]]; then echo "" # this is a configuration setting - if [[ "$gvm_auto_answer" == "false" ]]; then + if [[ "$gvm_auto_selfupdate" != "true" ]]; then echo -n "Would you like to upgrade now? (Y/n)" read upgrade fi @@ -212,6 +212,8 @@ if [[ "$gvm_suggestive_selfupdate" == "true" ]]; then if [[ "$upgrade" == "Y" || "$upgrade" == "y" ]]; then __gvmtool_selfupdate unset upgrade + else + echo "Not upgrading now..." fi fi fi diff --git a/src/test/groovy/gvm/BootstrapSpec.groovy b/src/test/groovy/gvm/BootstrapSpec.groovy index 26f45cc6..c5d7c330 100644 --- a/src/test/groovy/gvm/BootstrapSpec.groovy +++ b/src/test/groovy/gvm/BootstrapSpec.groovy @@ -11,25 +11,21 @@ class BootstrapSpec extends Specification { File gvmBaseDir String gvmBaseEnv + String bootstrap void setup(){ gvmBaseDir = prepareBaseDir() gvmBaseEnv = gvmBaseDir.absolutePath + bootstrap = "${gvmBaseDir.absolutePath}/.gvm/bin/gvm-init.sh" + curlStub = CurlStub.prepareIn(new File(gvmBaseDir, "bin")) - curlStub.primeWith("echo x.y.b") - - bash = GvmBashEnvBuilder - .create(gvmBaseDir) - .withCurlStub(curlStub) - .build() - - bash.start() } void "should set gvm version"(){ given: - def bootstrap = "${gvmBaseDir.absolutePath}/.gvm/bin/gvm-init.sh" + bash = GvmBashEnvBuilder.create(gvmBaseDir).build() + bash.start() bash.execute("source $bootstrap") when: @@ -39,6 +35,80 @@ class BootstrapSpec extends Specification { bash.output.contains "x.y.z" } + void "should suggest selfupdate on new version available if no suggestive selfupdate configuration found"() { + given: + curlStub.primeWith("http://localhost:8080/app/version", "echo x.y.b").build() + bash = GvmBashEnvBuilder + .create(gvmBaseDir) + .withCurlStub(curlStub) + .build() + bash.start() + + when: + bash.execute("source $bootstrap", ["N"]) + + then: + bash.output.contains "A new version of GVM is available..." + bash.output.contains "The current version is x.y.b, but you have x.y.z." + bash.output.contains "Would you like to upgrade now?" + + then: + bash.output.contains "Not upgrading now..." + + } + + void "should suggest selfupdate on new version available if suggestive selfupdate configuration found"() { + given: + curlStub.primeWith("http://localhost:8080/app/version", "echo x.y.b").build() + bash = GvmBashEnvBuilder + .create(gvmBaseDir) + .withCurlStub(curlStub) + .withConfiguration("gvm_suggestive_selfupdate", "true") + .build() + bash.start() + + when: + bash.execute("source $bootstrap", ["N"]) + + then: + bash.output.contains "A new version of GVM is available..." + bash.output.contains "The current version is x.y.b, but you have x.y.z." + bash.output.contains "Would you like to upgrade now?" + + then: + bash.output.contains "Not upgrading now..." + + } + + void "should not suggest selfupdate on new version if auto selfupdate configuration found"() { + given: + bash = GvmBashEnvBuilder + .create(gvmBaseDir) + .withCurlStub(curlStub) + .withConfiguration("gvm_auto_selfupdate", "true") + .build() + bash.start() + + and: + curlStub.primeWith("http://localhost:8080/app/version", "echo x.y.b") + .primeWith("http://localhost:8080/selfupdate", "echo echo 'Performing selfupdate.'") + .build() + + when: + bash.execute("source $bootstrap") + + then: + bash.output.contains "A new version of GVM is available..." + bash.output.contains "The current version is x.y.b, but you have x.y.z." + ! bash.output.contains("Would you like to upgrade now?") + + then: + bash.output.contains("Performing selfupdate.") + + } + + + void cleanup(){ bash.stop() assert gvmBaseDir.deleteDir() diff --git a/src/test/groovy/gvm/GvmBashEnvBuilder.groovy b/src/test/groovy/gvm/GvmBashEnvBuilder.groovy index 14eb673d..1b88d78c 100644 --- a/src/test/groovy/gvm/GvmBashEnvBuilder.groovy +++ b/src/test/groovy/gvm/GvmBashEnvBuilder.groovy @@ -16,7 +16,9 @@ class GvmBashEnvBuilder { String broadcast = "This is a LIVE broadcast!" String service = "http://localhost:8080" String jdkHome = "/path/to/my/jdk" - Map config = [:] + Map config = [ + gvm_auto_answer:'false' + ] File gvmDir, gvmBinDir, gvmVarDir, gvmSrcDir, gvmEtcDir, gvmExtDir, gvmArchivesDir, gvmTmpDir @@ -123,7 +125,7 @@ class GvmBashEnvBuilder { private initializeConfiguration(File targetFolder, Map config){ def configFile = new File(targetFolder, "config") config.each { key, value -> - configFile << "$key=$value" + configFile << "$key=$value\n" } }