Skip to content

Commit

Permalink
🐛 : fix non final versions in cli list
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubuisson committed Aug 9, 2019
1 parent 3d258cf commit 862652c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,7 +64,6 @@ public List<String> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 "<a href=\"/terraform/1.0.0/\">terraform_1.0.0</a>" +
"<a href=\"/terraform/0.12.5/\">terraform_0.12.5</a>" +
"<a href=\"/terraform/0.12.4/\">terraform_0.12.4</a>" +
"<a href=\"/terraform/0.12.3/\">terraform_0.12.3</a>" +
"<a href=\"/terraform/0.12.2/\">terraform_0.12.2</a>" +
"<a href=\"/terraform/0.12.1/\">terraform_0.12.1</a>" +
"<a href=\"/terraform/0.12.0/\">terraform_0.12.0</a>" +
"<a href=\"/terraform/0.12.0-rc1/\">terraform_0.12.0-rc1</a>" +
"<a href=\"/terraform/0.12.0-beta2/\">terraform_0.12.0-beta2</a>" +
"<a href=\"/terraform/0.12.0-beta1/\">terraform_0.12.0-beta1</a>" +
"<a href=\"/terraform/0.12.0-alpha4/\">terraform_0.12.0-alpha4</a>" +
"<a href=\"/terraform/0.12.0-alpha3/\">terraform_0.12.0-alpha3</a>" +
"<a href=\"/terraform/0.12.0-alpha2/\">terraform_0.12.0-alpha2</a>" +
"<a href=\"/terraform/0.12.0-alpha1/\">terraform_0.12.0-alpha1</a>" +
"<a href=\"/terraform/0.11.14/\">terraform_0.11.15-oci</a>" +
"<a href=\"/terraform/0.11.14/\">terraform_0.11.14</a>" +
"<a href=\"/terraform/0.11.13/\">terraform_0.11.13</a>" +
"<a href=\"/terraform/0.11.12/\">terraform_0.11.12</a>" +
"<a href=\"/terraform/0.11.12-beta1/\">terraform_0.11.12-beta1</a>" +
"<a href=\"/terraform/0.11.11/\">terraform_0.11.11</a>" +
"<a href=\"/terraform/0.11.10/\">terraform_0.11.10</a>" +
"<a href=\"/terraform/0.11.9/\">terraform_0.11.9</a>" +
"<a href=\"/terraform/0.11.9-beta1/\">terraform_0.11.9-beta1</a>" +
"<a href=\"/terraform/0.11.8/\">terraform_0.11.8</a>" +
"<a href=\"/terraform/0.11.7/\">terraform_0.11.7</a>" +
"<a href=\"/terraform/0.11.6/\">terraform_0.11.6</a>" +
"<a href=\"/terraform/0.11.5/\">terraform_0.11.5</a>" +
"<a href=\"/terraform/0.11.4/\">terraform_0.11.4</a>" +
"<a href=\"/terraform/0.11.3/\">terraform_0.11.3</a>" +
"<a href=\"/terraform/0.11.2/\">terraform_0.11.2</a>" +
"<a href=\"/terraform/0.11.1/\">terraform_0.11.1</a>" +
"<a href=\"/terraform/0.11.0/\">terraform_0.11.0</a>" +
"<a href=\"/terraform/0.11.0-rc1/\">terraform_0.11.0-rc1</a>" +
"<a href=\"/terraform/0.11.0-beta1/\">terraform_0.11.0-beta1</a>" +
"<a href=\"/terraform/../\">terraform_..</a>";
}

Expand Down

0 comments on commit 862652c

Please sign in to comment.