-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Split transport version func test into abstract base #133035
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
...roovy/org/elasticsearch/gradle/internal/transport/AbstractTransportVersionFuncTest.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal.transport | ||
|
||
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest | ||
import org.gradle.testkit.runner.BuildResult | ||
import org.gradle.testkit.runner.TaskOutcome | ||
|
||
class AbstractTransportVersionFuncTest extends AbstractGradleFuncTest { | ||
def javaResource(String project, String path, String content) { | ||
file("${project}/src/main/resources/${path}").withWriter { writer -> | ||
writer << content | ||
} | ||
} | ||
|
||
def javaSource(String project, String packageName, String className, String imports, String content) { | ||
String packageSlashes = packageName.replace('.', '/') | ||
file("${project}/src/main/java/${packageSlashes}/${className}.java").withWriter { writer -> | ||
writer << """ | ||
package ${packageName}; | ||
${imports} | ||
public class ${className} { | ||
${content} | ||
} | ||
""" | ||
} | ||
} | ||
|
||
def namedTransportVersion(String name, String ids) { | ||
javaResource("myserver", "transport/definitions/named/" + name + ".csv", ids) | ||
} | ||
|
||
def unreferencedTransportVersion(String name, String id) { | ||
javaResource("myserver", "transport/definitions/unreferenced/" + name + ".csv", id) | ||
} | ||
|
||
def definedAndUsedTransportVersion(String name, String ids) { | ||
return definedAndUsedTransportVersion(name, ids, "Test${name.capitalize()}") | ||
} | ||
|
||
def definedAndUsedTransportVersion(String name, String ids, String classname) { | ||
javaSource("myserver", "org.elasticsearch", classname, "", """ | ||
static final TransportVersion usage = TransportVersion.fromName("${name}"); | ||
""") | ||
namedTransportVersion(name, ids) | ||
} | ||
|
||
def latestTransportVersion(String branch, String name, String id) { | ||
javaResource("myserver", "transport/latest/" + branch + ".csv","${name},${id}") | ||
} | ||
|
||
def validateReferencesFails(String project) { | ||
return gradleRunner(":${project}:validateTransportVersionReferences").buildAndFail() | ||
} | ||
|
||
def validateDefinitionsFails() { | ||
return gradleRunner(":myserver:validateTransportVersionDefinitions").buildAndFail() | ||
} | ||
|
||
def assertReferencesFailure(BuildResult result, String project, String expectedOutput) { | ||
result.task(":${project}:validateTransportVersionReferences").outcome == TaskOutcome.FAILED | ||
assertOutputContains(result.output, expectedOutput) | ||
} | ||
|
||
def assertDefinitionsFailure(BuildResult result, String expectedOutput) { | ||
result.task(":myserver:validateTransportVersionDefinitions").outcome == TaskOutcome.FAILED | ||
assertOutputContains(result.output, expectedOutput) | ||
} | ||
|
||
def setup() { | ||
configurationCacheCompatible = false | ||
internalBuild() | ||
settingsFile << """ | ||
include ':myserver' | ||
include ':myplugin' | ||
""" | ||
file("gradle.properties") << """ | ||
org.elasticsearch.transport.definitionsProject=:myserver | ||
""" | ||
|
||
file("myserver/build.gradle") << """ | ||
apply plugin: 'java-library' | ||
apply plugin: 'elasticsearch.transport-version-references' | ||
apply plugin: 'elasticsearch.transport-version-resources' | ||
""" | ||
namedTransportVersion("existing_91", "8012000") | ||
namedTransportVersion("existing_92", "8123000,8012001") | ||
unreferencedTransportVersion("initial_9_0_0", "8000000") | ||
latestTransportVersion("9.2", "existing_92", "8123000") | ||
latestTransportVersion("9.1", "existing_92", "8012001") | ||
// a mock version of TransportVersion, just here so we can compile Dummy.java et al | ||
javaSource("myserver", "org.elasticsearch", "TransportVersion", "", """ | ||
public static TransportVersion fromName(String name) { | ||
return null; | ||
} | ||
""") | ||
javaSource("myserver", "org.elasticsearch", "Dummy", "", """ | ||
static final TransportVersion existing91 = TransportVersion.fromName("existing_91"); | ||
static final TransportVersion existing92 = TransportVersion.fromName("existing_92"); | ||
""") | ||
|
||
file("myplugin/build.gradle") << """ | ||
apply plugin: 'java-library' | ||
apply plugin: 'elasticsearch.transport-version-references' | ||
|
||
dependencies { | ||
implementation project(":myserver") | ||
} | ||
""" | ||
|
||
setupLocalGitRepo() | ||
execute("git checkout -b main") | ||
execute("git checkout -b test") | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These TVs are specific to the transport version tests, WDYT about moving them to a
setup()
method there?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.
They aren't specific to validation, they're a basic setup for all transport version tests, so i think they belong here. A test for generation would also need this basic setup of some named versions and latest files.