From ae4806daba45607a624dec37e95c2edfdca94b31 Mon Sep 17 00:00:00 2001 From: Rishikesh1159 Date: Fri, 11 Feb 2022 17:22:33 +0000 Subject: [PATCH] Adding test to check if correct IVY repos were added Signed-off-by: Rishikesh1159 --- .../gradle/DistributionDownloadPlugin.java | 4 -- .../DistributionDownloadPluginTests.java | 44 +++++++++++++++---- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/buildSrc/src/main/java/org/opensearch/gradle/DistributionDownloadPlugin.java b/buildSrc/src/main/java/org/opensearch/gradle/DistributionDownloadPlugin.java index 1ad22b631240b..8b5e81bc2ef07 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/DistributionDownloadPlugin.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/DistributionDownloadPlugin.java @@ -176,10 +176,6 @@ private static void addIvyRepo(Project project, String name, String url, String exclusiveContentRepository.filter(config -> config.includeGroup(group)); exclusiveContentRepository.forRepositories(repos.toArray(new IvyArtifactRepository[repos.size()])); }); - // set testCustomDistributionUrlProperty with url passed as parameter - if (project.findProperty("customDistributionUrl") != null) { - project.getExtensions().getExtraProperties().set("testCustomDistributionUrlProperty", url); - } } private static void addIvyRepo2(Project project, String name, String url, String group) { diff --git a/buildSrc/src/test/java/org/opensearch/gradle/DistributionDownloadPluginTests.java b/buildSrc/src/test/java/org/opensearch/gradle/DistributionDownloadPluginTests.java index 888f94c5950f0..95a095325587d 100644 --- a/buildSrc/src/test/java/org/opensearch/gradle/DistributionDownloadPluginTests.java +++ b/buildSrc/src/test/java/org/opensearch/gradle/DistributionDownloadPluginTests.java @@ -38,6 +38,7 @@ import org.opensearch.gradle.test.GradleUnitTestCase; import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.Project; +import org.gradle.api.internal.artifacts.repositories.DefaultIvyArtifactRepository; import org.gradle.testfixtures.ProjectBuilder; import java.io.File; @@ -79,25 +80,52 @@ public void testVersionDefault() { assertEquals(distro.getVersion(), VersionProperties.getOpenSearch()); } - public void testCustomDistributionUrlForNull() { - Project project = createProject(null, false); - assertNull(project.findProperty("customDistributionUrl")); - } - public void testCustomDistributionUrlWithUrl() { Project project = createProject(null, false); - String customUrl = "https://artifacts.opensearch.org"; + String customUrl = "https://artifacts.opensearch.org/custom"; project.getExtensions().getExtraProperties().set("customDistributionUrl", customUrl); DistributionDownloadPlugin plugin = project.getPlugins().getPlugin(DistributionDownloadPlugin.class); plugin.setupDistributions(project); - assertEquals(project.property("testCustomDistributionUrlProperty").toString(), customUrl); + assertEquals(4, project.getRepositories().size()); + assertEquals( + ((DefaultIvyArtifactRepository) project.getRepositories().getAt("opensearch-downloads")).getUrl().toString(), + customUrl + ); + assertEquals( + ((DefaultIvyArtifactRepository) project.getRepositories().getAt("opensearch-snapshots")).getUrl().toString(), + customUrl + ); + assertEquals( + ((DefaultIvyArtifactRepository) project.getRepositories().getAt("elasticsearch-downloads")).getUrl().toString(), + "https://artifacts-no-kpi.elastic.co" + ); + assertEquals( + ((DefaultIvyArtifactRepository) project.getRepositories().getAt("elasticsearch-snapshots")).getUrl().toString(), + "https://snapshots-no-kpi.elastic.co" + ); } public void testCustomDistributionUrlWithoutUrl() { Project project = createProject(null, false); DistributionDownloadPlugin plugin = project.getPlugins().getPlugin(DistributionDownloadPlugin.class); plugin.setupDistributions(project); - assertFalse(project.hasProperty("testCustomDistributionUrlProperty")); + assertEquals(5, project.getRepositories().size()); + assertEquals( + ((DefaultIvyArtifactRepository) project.getRepositories().getAt("opensearch-downloads")).getUrl().toString(), + "https://artifacts.opensearch.org" + ); + assertEquals( + ((DefaultIvyArtifactRepository) project.getRepositories().getAt("opensearch-snapshots")).getUrl().toString(), + "https://artifacts.opensearch.org" + ); + assertEquals( + ((DefaultIvyArtifactRepository) project.getRepositories().getAt("elasticsearch-downloads")).getUrl().toString(), + "https://artifacts-no-kpi.elastic.co" + ); + assertEquals( + ((DefaultIvyArtifactRepository) project.getRepositories().getAt("elasticsearch-snapshots")).getUrl().toString(), + "https://snapshots-no-kpi.elastic.co" + ); } public void testBadVersionFormat() {