Skip to content

Commit

Permalink
Merge pull request #130 from darxriggs/improve-infra-mock
Browse files Browse the repository at this point in the history
Improve Infra mock in PiplineUnit
  • Loading branch information
oleg-nenashev committed Jan 14, 2020
2 parents db1e87e + 0941aec commit b36e6ee
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
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() { }
}

0 comments on commit b36e6ee

Please sign in to comment.