-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Override Default Distribution Download Url with Custom Distribution Url When User Passes a Url #2086
Override Default Distribution Download Url with Custom Distribution Url When User Passes a Url #2086
Changes from 3 commits
1bd18b0
ae4806d
5944093
00d8023
17bcb6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,6 +80,58 @@ public void testVersionDefault() { | |
assertEquals(distro.getVersion(), VersionProperties.getOpenSearch()); | ||
} | ||
|
||
public void testCustomDistributionUrlWithUrl() { | ||
Project project = createProject(null, false); | ||
String customUrl = "https://artifacts.opensearch.org/custom"; | ||
project.getExtensions().getExtraProperties().set("customDistributionUrl", customUrl); | ||
DistributionDownloadPlugin plugin = project.getPlugins().getPlugin(DistributionDownloadPlugin.class); | ||
plugin.setupDistributions(project); | ||
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); | ||
assertEquals(5, project.getRepositories().size()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we still get 5 here? (And check for 4 below) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of when we not pass customDistribution URL to setupDownloadService() it goes to else block and calls addIvyRepo() with releases and release-candidates as last two parameters for PATTERN LAYOUT. In case when we pass customDistributionUrl PATTERN LAYOUT will be empty. code: in setupDownloadService() else block addIvyRepo( In addIvyRepo() method we have Arrays.stream() which iterates through PATTERN LAYOUT parameter for two times and create two separate repos one for releases and one for release-candidates but both having same url. So, this is why we have 5 repos added instead of 4 for case of not passing custom Distribution url. code: in addIvyRepo() private static void addIvyRepo(Project project, String name, String url, String group, String... patternLayout) { There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My question is more what do we want to do about this? If the URL is the going to be the same all the time, the second one should be removed, shouldn't it? If not, adjust the test for now to check all values. I hit approve, but consider fixing this before merging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes URL will be same both times. But I think either if we want to remove the second repo from repositories set or add a test check(opensearch-downloads2) again for same URL, we need to perform extra operation. Please correct me if I am wrong, adjusting the test to check all values would be like an extra safe step and better than removing repo. So, I will add test (checking opensearch-downloads2) to check all values as you mentioned in your previous suggestion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. works for me. |
||
assertEquals( | ||
((DefaultIvyArtifactRepository) project.getRepositories().getAt("opensearch-downloads")).getUrl().toString(), | ||
"https://artifacts.opensearch.org" | ||
); | ||
assertEquals( | ||
((DefaultIvyArtifactRepository) project.getRepositories().getAt("opensearch-downloads2")).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() { | ||
assertDistroError( | ||
createProject(null, false), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking a bit. This is a doc, so instead of "we can override ..." write "To override ..." and instead of "This will help" with "This enables to ..." or "This allows to pull artifacts from a custom location."
url -> URL
Remove "Sample command: ",
quote
the example on its own line, and replace "custom distribution download url" with an actual URL that one might want to use.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will make these changes.