From 862652c475ed7fff4edeb8045850fe7a35c0a265 Mon Sep 17 00:00:00 2001 From: Cyril Dubuisson Date: Fri, 9 Aug 2019 11:03:14 +0200 Subject: [PATCH] :bug: : fix non final versions in cli list --- .../repository/TerraformCLIRepository.java | 3 +- .../TerraformCLIRepositoryTest.java | 32 ++++--------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/main/java/io/codeka/gaia/repository/TerraformCLIRepository.java b/src/main/java/io/codeka/gaia/repository/TerraformCLIRepository.java index 1e8684c87..137c8dd19 100644 --- a/src/main/java/io/codeka/gaia/repository/TerraformCLIRepository.java +++ b/src/main/java/io/codeka/gaia/repository/TerraformCLIRepository.java @@ -18,7 +18,7 @@ @Repository public class TerraformCLIRepository { - private static final Pattern TERRAFORM_VERSION_PATTERN = Pattern.compile("terraform_([\\d]+.[\\d]+.[\\d]+)"); + private static final Pattern TERRAFORM_VERSION_PATTERN = Pattern.compile("terraform_([\\d]+.[\\d]+.[\\d]+)[^-]"); private static final Pattern SEMVER_PATTERN = Pattern.compile("([\\d]*).([\\d]*).([\\d]*)"); private String terraformReleasesUrl; @@ -64,7 +64,6 @@ public List listCLIVersion() { .matcher(response.getBody()) .results() .map(m -> m.group(1)) - .distinct() // to remove duplicate generating by alpha, beta, rc... .filter(this::isVersionAccepted) .collect(Collectors.toList()); } diff --git a/src/test/java/io/codeka/gaia/repository/TerraformCLIRepositoryTest.java b/src/test/java/io/codeka/gaia/repository/TerraformCLIRepositoryTest.java index 0a15494b7..883f71b3b 100644 --- a/src/test/java/io/codeka/gaia/repository/TerraformCLIRepositoryTest.java +++ b/src/test/java/io/codeka/gaia/repository/TerraformCLIRepositoryTest.java @@ -25,7 +25,7 @@ class TerraformCLIRepositoryTest { @BeforeEach void setup() { - repository = new TerraformCLIRepository("test_url", "0.11.3", restTemplate); + repository = new TerraformCLIRepository("test_url", "0.11.13", restTemplate); when(restTemplate.exchange(eq("test_url"), eq(HttpMethod.GET), any(HttpEntity.class), eq(String.class))) .thenReturn(ResponseEntity.ok(getVersions())); } @@ -36,7 +36,7 @@ void listCLIVersion_shouldReturnVersions() { var result = repository.listCLIVersion(); // then - assertThat(result).isNotNull().isNotEmpty().hasSize(19); + assertThat(result).isNotNull().isNotEmpty().hasSize(4); } @Test @@ -46,6 +46,7 @@ void listCLIVersion_shouldIgnoreNonFinalVersions() { // then assertThat(result).noneMatch(s -> s.contains("rc") || s.contains("beta") || s.contains("alpha")); + assertThat(result).doesNotContain("0.11.15"); // 0.11.15 exist only as 0.11.15-oci, so it should be excluded } @Test @@ -55,44 +56,23 @@ void listCLIVersion_shouldIgnoreVersionsLowerThanRequired() { // then assertThat(result) - .doesNotContain("0.11.0", "0.11.1", "0.11.2") - .contains("0.11.3"); + .doesNotContain("0.11.10", "0.11.11", "0.11.12") + .contains("0.11.13"); } private String getVersions() { return "terraform_1.0.0" + - "terraform_0.12.5" + - "terraform_0.12.4" + - "terraform_0.12.3" + - "terraform_0.12.2" + - "terraform_0.12.1" + "terraform_0.12.0" + "terraform_0.12.0-rc1" + - "terraform_0.12.0-beta2" + "terraform_0.12.0-beta1" + - "terraform_0.12.0-alpha4" + - "terraform_0.12.0-alpha3" + - "terraform_0.12.0-alpha2" + "terraform_0.12.0-alpha1" + + "terraform_0.11.15-oci" + "terraform_0.11.14" + "terraform_0.11.13" + "terraform_0.11.12" + "terraform_0.11.12-beta1" + "terraform_0.11.11" + "terraform_0.11.10" + - "terraform_0.11.9" + - "terraform_0.11.9-beta1" + - "terraform_0.11.8" + - "terraform_0.11.7" + - "terraform_0.11.6" + - "terraform_0.11.5" + - "terraform_0.11.4" + - "terraform_0.11.3" + - "terraform_0.11.2" + - "terraform_0.11.1" + - "terraform_0.11.0" + - "terraform_0.11.0-rc1" + - "terraform_0.11.0-beta1" + "terraform_.."; }