Skip to content
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

Improve Infra mock in PiplineUnit #130

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/test/groovy/PublishReportsStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PublishReportsStepTests extends BasePipelineTest {

binding.setVariable('env', env)
binding.setProperty('docker', new Docker())
binding.setProperty('infra', new Infra(true))
binding.setProperty('infra', new Infra(trusted: true))

helper.registerAllowedMethod('error', [String.class], {s ->
updateBuildStatus('FAILURE')
Expand All @@ -32,7 +32,7 @@ class PublishReportsStepTests extends BasePipelineTest {
@Test
void test_without_trusted_infra() throws Exception {
def script = loadScript(scriptName)
binding.setProperty('infra', new Infra(false))
binding.setProperty('infra', new Infra(trusted: false))
// when running with !infra.isTrusted()
try {
script.call(null)
Expand Down
2 changes: 1 addition & 1 deletion src/test/groovy/RunBenchmarksStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RunBenchmarksStepTests extends BasePipelineTest {
super.setUp()

binding.setVariable('env', env)
binding.setProperty('infra', new Infra(true))
binding.setProperty('infra', new Infra(trusted: true))

helper.registerAllowedMethod('archiveArtifacts', [Map.class], { m -> m })
helper.registerAllowedMethod('echo', [String.class], { s -> s })
Expand Down
38 changes: 25 additions & 13 deletions src/test/groovy/mock/Infra.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@ package mock
*/
class Infra implements Serializable {

private final boolean result
public Infra(boolean result) { this.result = result }
public Infra() { this.result = false }
public void checkout() { }
public void checkout(repo) { }
public String retrieveMavenSettingsFile(String location) { return location }
public String runWithMaven(String cmd) { return cmd }
public String runMaven(mvn) { return mvn }
public String runMaven(mvn, jdk, foo, settings) { return 'OK' }
public String runMaven(mvn, jdk, foo, settings, toolEnv) { return mvn }
public String runWithJava(command, jdk) { return command }
public String runWithJava(command, jdk, foo, toolEnv) { return command }
public boolean isTrusted() { return result }
private boolean trusted

public void checkout(String repo = null) { }

public String retrieveMavenSettingsFile(String location) {
return location
}

public Object runMaven(List<String> options, String jdk = null, List<String> extraEnv = null, String settingsFile = null, Boolean addToolEnv = null) {
def command = "mvn ${options.join(' ')}"
return runWithMaven(command, jdk, extraEnv, addToolEnv)
}

public Object runWithMaven(String command, String jdk = null, List<String> extraEnv = null, Boolean addToolEnv = null) {
return runWithJava(command, jdk, extraEnv, addToolEnv)
}

public Object runWithJava(String command, String jdk = null, List<String> extraEnv = null, Boolean addToolEnv = null) {
return command
}

public boolean isTrusted() {
return trusted
}

public void maybePublishIncrementals() { }
}