From 743975dcaa5d0b44fe89012987f11d2107e66ab9 Mon Sep 17 00:00:00 2001 From: Marco Vermeulen Date: Wed, 16 Nov 2016 09:07:31 +0000 Subject: [PATCH] Use new candidates/all endpoint for candidate cache in beta channel. --- src/main/bash/sdkman-init.sh | 6 +- ...vy => CandidatesCacheBootstrapSpec.groovy} | 62 ++++++++++++++++++- 2 files changed, 64 insertions(+), 4 deletions(-) rename src/test/groovy/sdkman/specs/{CandidatesFileBootstrapSpec.groovy => CandidatesCacheBootstrapSpec.groovy} (63%) diff --git a/src/main/bash/sdkman-init.sh b/src/main/bash/sdkman-init.sh index 574265cf..dd9bba63 100644 --- a/src/main/bash/sdkman-init.sh +++ b/src/main/bash/sdkman-init.sh @@ -117,7 +117,11 @@ SDKMAN_CANDIDATES_CACHE="${SDKMAN_DIR}/var/candidates" if [[ -f "$SDKMAN_CANDIDATES_CACHE" && -z "$(find "$SDKMAN_CANDIDATES_CACHE" -mmin +$((60*24)))" ]]; then SDKMAN_CANDIDATES_CSV=$(cat "$SDKMAN_CANDIDATES_CACHE") else - SDKMAN_CANDIDATES_CSV=$(__sdkman_secure_curl "${SDKMAN_LEGACY_API}/candidates") + if [[ "$sdkman_beta_channel" == 'true' ]]; then + SDKMAN_CANDIDATES_CSV=$(__sdkman_secure_curl "${SDKMAN_CURRENT_API}/candidates/all") + else + SDKMAN_CANDIDATES_CSV=$(__sdkman_secure_curl "${SDKMAN_LEGACY_API}/candidates") + fi echo "$SDKMAN_CANDIDATES_CSV" > "$SDKMAN_CANDIDATES_CACHE" fi diff --git a/src/test/groovy/sdkman/specs/CandidatesFileBootstrapSpec.groovy b/src/test/groovy/sdkman/specs/CandidatesCacheBootstrapSpec.groovy similarity index 63% rename from src/test/groovy/sdkman/specs/CandidatesFileBootstrapSpec.groovy rename to src/test/groovy/sdkman/specs/CandidatesCacheBootstrapSpec.groovy index d2ae9cbe..b93ac1b5 100644 --- a/src/test/groovy/sdkman/specs/CandidatesFileBootstrapSpec.groovy +++ b/src/test/groovy/sdkman/specs/CandidatesCacheBootstrapSpec.groovy @@ -2,11 +2,16 @@ package sdkman.specs import sdkman.support.SdkmanEnvSpecification -class CandidatesFileBootstrapSpec extends SdkmanEnvSpecification { +class CandidatesCacheBootstrapSpec extends SdkmanEnvSpecification { - static final LEGACY_API = "http://localhost:8080/1" + static final TWO_DAYS_IN_MILLIS = 24 * 61 * 60 * 1000 + + static final LEGACY_API = "http://localhost:8080" static final LEGACY_CANDIDATES_ENDPOINT = "$LEGACY_API/candidates" + static final CURRENT_API = "http://localhost:8080" + static final CURRENT_CANDIDATES_ENDPOINT = "$CURRENT_API/candidates/all" + File candidatesFile def setup() { @@ -55,7 +60,7 @@ class CandidatesFileBootstrapSpec extends SdkmanEnvSpecification { .withLegacyService(LEGACY_API) .withAvailableCandidates(['groovy']) .build() - def twoDaysAgo = System.currentTimeMillis() - (24 * 61 * 60 * 1000) + def twoDaysAgo = System.currentTimeMillis() - TWO_DAYS_IN_MILLIS candidatesFile.setLastModified(twoDaysAgo) and: @@ -124,4 +129,55 @@ class CandidatesFileBootstrapSpec extends SdkmanEnvSpecification { candidatesFile.text.contains(candidates.join(',')) } + void "should query current api if subscribed to beta channel"() { + given: 'a working sdkman installation with expired candidates' + curlStub.primeWith(CURRENT_CANDIDATES_ENDPOINT, "echo groovy,java,scala") + bash = sdkmanBashEnvBuilder + .withLegacyService(LEGACY_API) + .withCurrentService(CURRENT_API) + .withConfiguration("sdkman_beta_channel", "true") + .withAvailableCandidates(['groovy']) + .build() + + and: + def twoDaysAgo = System.currentTimeMillis() - TWO_DAYS_IN_MILLIS + candidatesFile.setLastModified(twoDaysAgo) + + and: + bash.start() + + when: 'bootstrap the system' + bash.execute("source $bootstrapScript") + + then: + candidatesFile.exists() + candidatesFile.text.contains('groovy,java,scala') + } + + void "should query legacy api if not subscribed to beta channel"() { + given: 'a working sdkman installation with expired candidates' + curlStub.primeWith(LEGACY_CANDIDATES_ENDPOINT, "echo groovy,scala") + bash = sdkmanBashEnvBuilder + .withLegacyService(LEGACY_API) + .withCurrentService(CURRENT_API) + .withConfiguration("sdkman_beta_channel", "false") + .withAvailableCandidates(['groovy']) + .build() + + and: + def twoDaysAgo = System.currentTimeMillis() - TWO_DAYS_IN_MILLIS + candidatesFile.setLastModified(twoDaysAgo) + + and: + bash.start() + + when: 'bootstrap the system' + bash.execute("source $bootstrapScript") + + then: + candidatesFile.exists() + candidatesFile.text.contains('groovy,scala') + } + + }