From 7471a591dd4e4030767ee9e274cc62a30d000091 Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Wed, 5 Feb 2020 17:41:40 -0500 Subject: [PATCH 1/2] Restore "Merge pull request #184 from kmanning/issue_87_part_3"" --- build.gradle | 1 + config/codenarc/codenarc.xml | 33 +++++++++++++++ src/AgentNodePlugin.groovy | 4 +- src/FileParametersPlugin.groovy | 4 +- src/Jenkinsfile.groovy | 3 +- src/RegressionStage.groovy | 2 +- src/S3BackendPlugin.groovy | 7 ++-- src/SemanticVersion.groovy | 17 ++++---- src/TerraformApplyCommand.groovy | 2 +- src/TerraformEnvironmentStage.groovy | 6 +-- src/TerraformInitCommand.groovy | 4 +- src/TerraformPlanCommand.groovy | 2 +- src/TerraformPlugin.groovy | 4 +- src/TerraformValidateCommand.groovy | 5 +-- src/TerraformValidateStage.groovy | 6 +-- src/TfvarsFilesPlugin.groovy | 4 +- test/AnsiColorPluginTest.groovy | 8 ++-- test/AwssumePluginTest.groovy | 16 ++++--- test/BuildGraphTest.groovy | 9 ++-- test/BuildStageTest.groovy | 12 +++--- test/ConditionalApplyPluginTest.groovy | 16 +++---- test/ConfirmApplyPluginTest.groovy | 12 ++++-- test/ConsulBackendPluginTest.groovy | 15 ++++--- test/CredentialsPluginTest.groovy | 14 +++++-- test/CrqPluginTest.groovy | 20 +++++---- test/DefaultEnvironmentPluginTest.groovy | 7 ++-- test/FileParametersPluginTest.groovy | 14 ++++--- test/JenkinsfileTest.groovy | 14 +++---- ...arameterStoreBuildWrapperPluginTest.groovy | 13 +++--- test/ParameterStoreExecPluginTest.groovy | 14 ++++--- test/RegressionStageTest.groovy | 17 ++++---- test/S3BackendPluginTest.groovy | 16 ++++--- test/SemanticVersionTest.groovy | 42 ++++++++++--------- test/TerraformApplyCommandTest.groovy | 20 +++++---- test/TerraformDirectoryPluginTest.groovy | 11 ++--- test/TerraformEnvironmentStageTest.groovy | 27 ++++++++---- test/TerraformInitCommandTest.groovy | 15 +++---- test/TerraformPlanCommandTest.groovy | 17 ++++---- test/TerraformPluginTest.groovy | 18 ++++---- test/TerraformPluginVersion11Test.groovy | 13 ++---- test/TerraformPluginVersion12Test.groovy | 17 ++++---- test/TerraformValidateCommandTest.groovy | 14 +++---- test/TfvarsFilesPluginTest.groovy | 12 +++--- test/WithAwsPluginTest.groovy | 15 ++++--- 44 files changed, 312 insertions(+), 230 deletions(-) create mode 100644 config/codenarc/codenarc.xml diff --git a/build.gradle b/build.gradle index c00331eb..9ab48bfe 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'groovy' apply plugin: 'jacoco' +apply plugin: 'codenarc' repositories { mavenCentral() diff --git a/config/codenarc/codenarc.xml b/config/codenarc/codenarc.xml new file mode 100644 index 00000000..6bb07059 --- /dev/null +++ b/config/codenarc/codenarc.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + diff --git a/src/AgentNodePlugin.groovy b/src/AgentNodePlugin.groovy index 4697bb15..5fb3b1c4 100644 --- a/src/AgentNodePlugin.groovy +++ b/src/AgentNodePlugin.groovy @@ -5,7 +5,7 @@ public class AgentNodePlugin implements TerraformValidateStagePlugin, TerraformE private static String dockerImage private static String dockerOptions - AgentNodePlugin() {} + AgentNodePlugin() { } public static void init() { def plugin = new AgentNodePlugin() @@ -37,7 +37,7 @@ public class AgentNodePlugin implements TerraformValidateStagePlugin, TerraformE public Closure addAgent() { return { closure -> if (dockerImage) { - docker.image(this.dockerImage).inside(this.dockerOptions){ + docker.image(this.dockerImage).inside(this.dockerOptions) { closure() } } else { diff --git a/src/FileParametersPlugin.groovy b/src/FileParametersPlugin.groovy index f9641637..e14fb316 100644 --- a/src/FileParametersPlugin.groovy +++ b/src/FileParametersPlugin.groovy @@ -1,7 +1,7 @@ -import groovy.text.StreamingTemplateEngine - import static TerraformEnvironmentStage.ALL +import groovy.text.StreamingTemplateEngine + class FileParametersPlugin implements TerraformEnvironmentStagePlugin { public static void init() { FileParametersPlugin plugin = new FileParametersPlugin() diff --git a/src/Jenkinsfile.groovy b/src/Jenkinsfile.groovy index 152299d8..67534773 100644 --- a/src/Jenkinsfile.groovy +++ b/src/Jenkinsfile.groovy @@ -44,7 +44,7 @@ class Jenkinsfile { def Map parseScmUrl(String scmUrl) { def matcher = scmUrl =~ /.*(?:\/\/|\@)[^\/:]+[\/:]([^\/]+)\/([^\/.]+)(.git)?/ - def Map results = new HashMap() + def Map results = [:] results.put("organization", matcher[0][1]) results.put("repo", matcher[0][2]) return results @@ -122,7 +122,6 @@ class Jenkinsfile { } throw new RuntimeException("Your pipeline has ${stages.size()} stages - the maximum supported by default is 7. Define a custom pipeline template and assign it to Jenkinsfile.pipelineTemplate to create your pipeline.") - } public getEnv() { diff --git a/src/RegressionStage.groovy b/src/RegressionStage.groovy index 075e1602..f59d16ec 100644 --- a/src/RegressionStage.groovy +++ b/src/RegressionStage.groovy @@ -1,7 +1,7 @@ class RegressionStage implements Stage { public String testCommand - public List automationRepoList = new ArrayList() + public List automationRepoList = [] private String testCommandDirectory private Closure existingDecorations diff --git a/src/S3BackendPlugin.groovy b/src/S3BackendPlugin.groovy index 8f99dbca..f01d9c56 100644 --- a/src/S3BackendPlugin.groovy +++ b/src/S3BackendPlugin.groovy @@ -20,7 +20,6 @@ class S3BackendPlugin implements TerraformInitCommandPlugin { configs['encrypt'] = getEncrypt(environment) configs['kms_key_id'] = getKmsKeyId(environment) - configs.each { entry -> if (entry.value?.trim()) { command.withBackendConfig("${entry.key}=${entry.value}") @@ -66,12 +65,12 @@ class S3BackendPlugin implements TerraformInitCommandPlugin { String region = env['S3_BACKEND_REGION'] if (region == null) { - println("No S3_BACKEND_REGION found - checking for environment-specific region") - region = env["${environment.toUpperCase()}_S3_BACKEND_REGION"] + println("No S3_BACKEND_REGION found - checking for environment-specific region") + region = env["${environment.toUpperCase()}_S3_BACKEND_REGION"] } if (region == null) { - region = env["${environment}_S3_BACKEND_REGION"] + region = env["${environment}_S3_BACKEND_REGION"] } if (region == null) { diff --git a/src/SemanticVersion.groovy b/src/SemanticVersion.groovy index 6c2a8ae7..a45a1e1e 100644 --- a/src/SemanticVersion.groovy +++ b/src/SemanticVersion.groovy @@ -1,5 +1,3 @@ -import java.util.Comparator; - class SemanticVersion implements Comparable { private String versionString @@ -20,26 +18,25 @@ class SemanticVersion implements Comparable { @Override int compareTo(SemanticVersion other) { - for(i in 0.. 1.0.1 : 1.0.1 <=> 1.0.1-rc1 } else if (i == other.components.size()) { return this.components[i].isInteger() ? 1 : -1 //1.0.1 <=> 1.0 : 1.0.1-rc1 <=> 1.0.1 } - if(this.components[i].isInteger() && other.components[i].isInteger()) { //1.0 <=> 1.1 or //1.1 <=> 1.0 + if (this.components[i].isInteger() && other.components[i].isInteger()) { //1.0 <=> 1.1 or //1.1 <=> 1.0 int diff = (this.components[i] as int) <=> (other.components[i] as int) - if(diff != 0) { + if (diff != 0) { return diff } - } else if(this.components[i].isInteger()) { //1.0.3.4 <=> 1.0.3.4b goes to the former. Hmm. + } else if (this.components[i].isInteger()) { //1.0.3.4 <=> 1.0.3.4b goes to the former. Hmm. return 1 - } else if(other.components[i].isInteger()) { //1.0.3.4-rc3 <=> 1.0.3.4 goes to the later. + } else if (other.components[i].isInteger()) { //1.0.3.4-rc3 <=> 1.0.3.4 goes to the later. return -1 } else { int diff = this.components[i] <=> other.components[i] //1.0.3.3 <=> 1.0.3.4 works at least. :-/ - if(diff != 0) { + if (diff != 0) { return diff } } diff --git a/src/TerraformApplyCommand.groovy b/src/TerraformApplyCommand.groovy index 49e4f402..573df6f7 100644 --- a/src/TerraformApplyCommand.groovy +++ b/src/TerraformApplyCommand.groovy @@ -54,7 +54,7 @@ class TerraformApplyCommand { private applyPluginsOnce() { def remainingPlugins = plugins - appliedPlugins - for(TerraformApplyCommandPlugin plugin in remainingPlugins) { + for (TerraformApplyCommandPlugin plugin in remainingPlugins) { plugin.apply(this) appliedPlugins << plugin } diff --git a/src/TerraformEnvironmentStage.groovy b/src/TerraformEnvironmentStage.groovy index fe83ec42..07dd67e4 100644 --- a/src/TerraformEnvironmentStage.groovy +++ b/src/TerraformEnvironmentStage.groovy @@ -18,7 +18,7 @@ class TerraformEnvironmentStage implements Stage { TerraformEnvironmentStage(String environment) { this.environment = environment this.jenkinsfile = Jenkinsfile.instance - this.decorations = new HashMap() + this.decorations = [:] } public Stage then(Stage nextStages) { @@ -106,7 +106,7 @@ class TerraformEnvironmentStage implements Stage { } } - decorations.put(stageName,newDecoration) + decorations.put(stageName, newDecoration) } private void applyDecorationsAround(String stageName, Closure stageClosure) { @@ -127,7 +127,7 @@ class TerraformEnvironmentStage implements Stage { public void applyPlugins() { // Apply both global and local plugins, in the correct order - for(plugin in getAllPlugins()) { + for (plugin in getAllPlugins()) { plugin.apply(this) } } diff --git a/src/TerraformInitCommand.groovy b/src/TerraformInitCommand.groovy index 15d4586b..d7462d2c 100644 --- a/src/TerraformInitCommand.groovy +++ b/src/TerraformInitCommand.groovy @@ -50,7 +50,7 @@ class TerraformInitCommand { if (!input) { pieces << "-input=false" } - if(doBackend) { + if (doBackend) { backendConfigs.each { config -> pieces << "-backend-config=${config}" } @@ -67,7 +67,7 @@ class TerraformInitCommand { private applyPluginsOnce() { def remainingPlugins = globalPlugins - appliedPlugins - for(TerraformInitCommandPlugin plugin in remainingPlugins) { + for (TerraformInitCommandPlugin plugin in remainingPlugins) { plugin.apply(this) appliedPlugins << plugin } diff --git a/src/TerraformPlanCommand.groovy b/src/TerraformPlanCommand.groovy index 6d559c48..1779a62f 100644 --- a/src/TerraformPlanCommand.groovy +++ b/src/TerraformPlanCommand.groovy @@ -55,7 +55,7 @@ class TerraformPlanCommand { private applyPluginsOnce() { def remainingPlugins = plugins - appliedPlugins - for(TerraformPlanCommandPlugin plugin in remainingPlugins) { + for (TerraformPlanCommandPlugin plugin in remainingPlugins) { plugin.apply(this) appliedPlugins << plugin } diff --git a/src/TerraformPlugin.groovy b/src/TerraformPlugin.groovy index 009e9b30..67efd27e 100644 --- a/src/TerraformPlugin.groovy +++ b/src/TerraformPlugin.groovy @@ -23,7 +23,7 @@ class TerraformPlugin implements TerraformValidateCommandPlugin, TerraformValida } public SemanticVersion detectVersion() { - if(version == null) { + if (version == null) { if (fileExists(TERRAFORM_VERSION_FILE)) { version = new SemanticVersion(readFile(TERRAFORM_VERSION_FILE)) } else { @@ -35,7 +35,7 @@ class TerraformPlugin implements TerraformValidateCommandPlugin, TerraformValida } public TerraformPluginVersion strategyFor(String version) { - if(new SemanticVersion(version).compareTo(new SemanticVersion('0.12.0')) >= 0) { + if (new SemanticVersion(version) >= new SemanticVersion('0.12.0')) { return new TerraformPluginVersion12() } diff --git a/src/TerraformValidateCommand.groovy b/src/TerraformValidateCommand.groovy index 3a6b3497..46c33d06 100644 --- a/src/TerraformValidateCommand.groovy +++ b/src/TerraformValidateCommand.groovy @@ -31,8 +31,7 @@ class TerraformValidateCommand { pieces = pieces + prefixes pieces << terraformBinary pieces << command - for(String argument in arguments) - { + for (String argument in arguments) { pieces << argument } if (directory) { @@ -44,7 +43,7 @@ class TerraformValidateCommand { private applyPluginsOnce() { def remainingPlugins = globalPlugins - appliedPlugins - for(TerraformValidateCommandPlugin plugin in remainingPlugins) { + for (TerraformValidateCommandPlugin plugin in remainingPlugins) { plugin.apply(this) appliedPlugins << plugin } diff --git a/src/TerraformValidateStage.groovy b/src/TerraformValidateStage.groovy index c941436f..c9b07d88 100644 --- a/src/TerraformValidateStage.groovy +++ b/src/TerraformValidateStage.groovy @@ -9,7 +9,7 @@ class TerraformValidateStage implements Stage { public TerraformValidateStage() { this.jenkinsfile = Jenkinsfile.instance - this.decorations = new HashMap() + this.decorations = [:] } public Stage then(Stage nextStage) { @@ -60,7 +60,7 @@ class TerraformValidateStage implements Stage { } } - decorations.put(stageName,newDecoration) + decorations.put(stageName, newDecoration) } private void applyDecorationsAround(String stageName, Closure stageClosure) { @@ -76,7 +76,7 @@ class TerraformValidateStage implements Stage { } public void applyPlugins() { - for(plugin in globalPlugins) { + for (plugin in globalPlugins) { plugin.apply(this) } } diff --git a/src/TfvarsFilesPlugin.groovy b/src/TfvarsFilesPlugin.groovy index 0146e625..cddd103a 100644 --- a/src/TfvarsFilesPlugin.groovy +++ b/src/TfvarsFilesPlugin.groovy @@ -19,7 +19,7 @@ class TfvarsFilesPlugin implements TerraformPlanCommandPlugin, TerraformApplyCom @Override void apply(TerraformApplyCommand command) { def environmentVarFile = "${directory}/${command.environment}.tfvars" - if(originalContext.fileExists(environmentVarFile)) { + if (originalContext.fileExists(environmentVarFile)) { command.withArgument("-var-file=${environmentVarFile}") } else { originalContext.echo "${environmentVarFile} does not exist." @@ -29,7 +29,7 @@ class TfvarsFilesPlugin implements TerraformPlanCommandPlugin, TerraformApplyCom @Override void apply(TerraformPlanCommand command) { def environmentVarFile = "${directory}/${command.environment}.tfvars" - if(originalContext.fileExists(environmentVarFile)) { + if (originalContext.fileExists(environmentVarFile)) { command.withArgument("-var-file=${environmentVarFile}") } else { originalContext.echo "${environmentVarFile} does not exist." diff --git a/test/AnsiColorPluginTest.groovy b/test/AnsiColorPluginTest.groovy index 00004bb3..d7b38484 100644 --- a/test/AnsiColorPluginTest.groovy +++ b/test/AnsiColorPluginTest.groovy @@ -1,9 +1,11 @@ -import static org.junit.Assert.* +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.junit.Assert.assertThat -import org.junit.* +import org.junit.Test +import org.junit.After import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class AnsiColorPluginTest { diff --git a/test/AwssumePluginTest.groovy b/test/AwssumePluginTest.groovy index 9728c33d..d1df256f 100644 --- a/test/AwssumePluginTest.groovy +++ b/test/AwssumePluginTest.groovy @@ -1,11 +1,17 @@ -import static org.junit.Assert.* +import static org.hamcrest.Matchers.containsString +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.hamcrest.Matchers.is +import static org.hamcrest.Matchers.not +import static org.junit.Assert.assertThat +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.mock; -import org.junit.* +import org.junit.After +import org.junit.Before +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.mock; -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class AwssumePluginTest { diff --git a/test/BuildGraphTest.groovy b/test/BuildGraphTest.groovy index 8391145b..e63bdeb3 100644 --- a/test/BuildGraphTest.groovy +++ b/test/BuildGraphTest.groovy @@ -1,11 +1,12 @@ -import static org.junit.Assert.* +import static org.mockito.Mockito.inOrder +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.times +import static org.mockito.Mockito.verify -import org.junit.* +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner import org.mockito.InOrder -import static org.mockito.Mockito.* -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class BuildGraphTest { diff --git a/test/BuildStageTest.groovy b/test/BuildStageTest.groovy index 312a0993..72e19a17 100644 --- a/test/BuildStageTest.groovy +++ b/test/BuildStageTest.groovy @@ -1,12 +1,10 @@ -import org.junit.* -import org.junit.runner.RunWith -import de.bechte.junit.runners.context.HierarchicalContextRunner - -import static org.mockito.Mockito.verify -import static org.mockito.Mockito.when import static org.mockito.Mockito.spy import static org.mockito.Mockito.doReturn +import org.junit.Test +import org.junit.runner.RunWith +import de.bechte.junit.runners.context.HierarchicalContextRunner + @RunWith(HierarchicalContextRunner.class) class BuildStageTest { @@ -15,7 +13,7 @@ class BuildStageTest { void buildsWithoutError() { BuildStage stage = spy(new BuildStage()) - doReturn({ -> }).when(stage).pipelineConfiguration() + doReturn { -> }.when(stage).pipelineConfiguration() stage.build() } diff --git a/test/ConditionalApplyPluginTest.groovy b/test/ConditionalApplyPluginTest.groovy index cc946576..4348a44b 100644 --- a/test/ConditionalApplyPluginTest.groovy +++ b/test/ConditionalApplyPluginTest.groovy @@ -1,14 +1,16 @@ -import static org.junit.Assert.* +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.junit.Assert.assertFalse +import static org.junit.Assert.assertThat +import static org.junit.Assert.assertTrue +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -import org.junit.* +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.hamcrest.Matchers.* -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.Matchers.* - @RunWith(HierarchicalContextRunner.class) class ConditionalApplyPluginTest { @After diff --git a/test/ConfirmApplyPluginTest.groovy b/test/ConfirmApplyPluginTest.groovy index 2239eec3..18b992d9 100644 --- a/test/ConfirmApplyPluginTest.groovy +++ b/test/ConfirmApplyPluginTest.groovy @@ -1,9 +1,13 @@ -import static org.junit.Assert.* - -import org.junit.* +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.junit.Assert.assertFalse +import static org.junit.Assert.assertThat +import static org.junit.Assert.assertTrue + +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class ConfirmApplyPluginTest { diff --git a/test/ConsulBackendPluginTest.groovy b/test/ConsulBackendPluginTest.groovy index 01ece859..665c77e5 100644 --- a/test/ConsulBackendPluginTest.groovy +++ b/test/ConsulBackendPluginTest.groovy @@ -1,11 +1,16 @@ -import static org.junit.Assert.* +import static org.hamcrest.Matchers.containsString +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.hamcrest.Matchers.not +import static org.junit.Assert.assertThat +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.mock; -import org.junit.* +import org.junit.After +import org.junit.Before +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.mock; -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class ConsulBackendPluginTest { diff --git a/test/CredentialsPluginTest.groovy b/test/CredentialsPluginTest.groovy index f15faae2..70075823 100644 --- a/test/CredentialsPluginTest.groovy +++ b/test/CredentialsPluginTest.groovy @@ -1,9 +1,15 @@ -import static org.junit.Assert.* - -import org.junit.* +import static org.hamcrest.Matchers.equalTo +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.hasSize +import static org.hamcrest.Matchers.instanceOf +import static org.hamcrest.Matchers.is +import static org.hamcrest.Matchers.notNullValue +import static org.junit.Assert.assertThat + +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class CredentialsPluginTest { diff --git a/test/CrqPluginTest.groovy b/test/CrqPluginTest.groovy index 3c16a15c..130ef716 100644 --- a/test/CrqPluginTest.groovy +++ b/test/CrqPluginTest.groovy @@ -1,14 +1,16 @@ -import static org.junit.Assert.* - -import org.junit.* +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.hamcrest.Matchers.is +import static org.junit.Assert.assertThat +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.spy +import static org.mockito.Mockito.verify +import static org.mockito.Mockito.when + +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mock; -import static org.mockito.Matchers.* -import static org.hamcrest.Matchers.* -import static org.mockito.Mockito.*; @RunWith(HierarchicalContextRunner.class) class CrqPluginTest { diff --git a/test/DefaultEnvironmentPluginTest.groovy b/test/DefaultEnvironmentPluginTest.groovy index 934963c7..d2390dd1 100644 --- a/test/DefaultEnvironmentPluginTest.groovy +++ b/test/DefaultEnvironmentPluginTest.groovy @@ -1,9 +1,10 @@ -import static org.junit.Assert.* +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.junit.Assert.assertThat -import org.junit.* +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class DefaultEnvironmentPluginTest { diff --git a/test/FileParametersPluginTest.groovy b/test/FileParametersPluginTest.groovy index 634b1a6e..903cc0f7 100644 --- a/test/FileParametersPluginTest.groovy +++ b/test/FileParametersPluginTest.groovy @@ -1,12 +1,14 @@ -import static org.junit.Assert.* +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.junit.Assert.assertEquals +import static org.junit.Assert.assertThat +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.spy; -import org.junit.* +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class FileParametersPluginTest { diff --git a/test/JenkinsfileTest.groovy b/test/JenkinsfileTest.groovy index f519998c..6f1ce005 100644 --- a/test/JenkinsfileTest.groovy +++ b/test/JenkinsfileTest.groovy @@ -1,14 +1,12 @@ -import static org.junit.Assert.* - -import org.junit.* -import org.junit.runner.RunWith -import de.bechte.junit.runners.context.HierarchicalContextRunner -import Jenkinsfile - +import static org.junit.Assert.assertEquals import static org.mockito.Mockito.mock import static org.mockito.Mockito.when -import static org.hamcrest.Matchers.* +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import de.bechte.junit.runners.context.HierarchicalContextRunner @RunWith(HierarchicalContextRunner.class) class JenkinsfileTest { diff --git a/test/ParameterStoreBuildWrapperPluginTest.groovy b/test/ParameterStoreBuildWrapperPluginTest.groovy index a05aade5..e75db74f 100644 --- a/test/ParameterStoreBuildWrapperPluginTest.groovy +++ b/test/ParameterStoreBuildWrapperPluginTest.groovy @@ -1,11 +1,14 @@ -import static org.junit.Assert.* +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.junit.Assert.assertEquals +import static org.junit.Assert.assertThat +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.when -import org.junit.* +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.mockito.Mockito.mock -import static org.mockito.Mockito.when -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class ParameterStoreBuildWrapperPluginTest { diff --git a/test/ParameterStoreExecPluginTest.groovy b/test/ParameterStoreExecPluginTest.groovy index 50340477..e0476dab 100644 --- a/test/ParameterStoreExecPluginTest.groovy +++ b/test/ParameterStoreExecPluginTest.groovy @@ -1,11 +1,15 @@ -import static org.junit.Assert.* +import static org.hamcrest.Matchers.containsString +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.junit.Assert.assertEquals +import static org.junit.Assert.assertThat +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.mock; -import org.junit.* +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.mock; -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class ParameterStoreExecPluginTest { diff --git a/test/RegressionStageTest.groovy b/test/RegressionStageTest.groovy index 93144fda..fde4be77 100644 --- a/test/RegressionStageTest.groovy +++ b/test/RegressionStageTest.groovy @@ -1,11 +1,12 @@ -import org.junit.* -import org.junit.runner.RunWith -import de.bechte.junit.runners.context.HierarchicalContextRunner - import static org.mockito.Mockito.mock import static org.mockito.Mockito.verify import static org.mockito.Mockito.when +import org.junit.After +import org.junit.Test +import org.junit.runner.RunWith +import de.bechte.junit.runners.context.HierarchicalContextRunner + @RunWith(HierarchicalContextRunner.class) class RegressionStageTest { @@ -23,7 +24,7 @@ class RegressionStageTest { } @Test - void automationRepoSpecifiedSuccessfullyCallApply(){ + void automationRepoSpecifiedSuccessfullyCallApply() { RegressionStagePlugin fakePlugin = mock(RegressionStagePlugin.class) RegressionStage.addPlugin(fakePlugin) @@ -35,7 +36,7 @@ class RegressionStageTest { } @Test - void automationRepoAndAppRepoSpecifiedSuccessfullyCallApply(){ + void automationRepoAndAppRepoSpecifiedSuccessfullyCallApply() { RegressionStagePlugin fakePlugin = mock(RegressionStagePlugin.class) RegressionStage.addPlugin(fakePlugin) @@ -48,7 +49,7 @@ class RegressionStageTest { } @Test - void automationRepoAndAppRepoWithChangeDirectorySpecifiedSuccessfullyCallApply(){ + void automationRepoAndAppRepoWithChangeDirectorySpecifiedSuccessfullyCallApply() { RegressionStagePlugin fakePlugin = mock(RegressionStagePlugin.class) RegressionStage.addPlugin(fakePlugin) @@ -62,7 +63,7 @@ class RegressionStageTest { } @Test - void noAutomationRepoSpecifiedSuccessfullyCallApply(){ + void noAutomationRepoSpecifiedSuccessfullyCallApply() { RegressionStagePlugin fakePlugin = mock(RegressionStagePlugin.class) RegressionStage.addPlugin(fakePlugin) diff --git a/test/S3BackendPluginTest.groovy b/test/S3BackendPluginTest.groovy index e32ffcf9..5467c53d 100644 --- a/test/S3BackendPluginTest.groovy +++ b/test/S3BackendPluginTest.groovy @@ -1,12 +1,16 @@ -import static org.junit.Assert.* +import static org.hamcrest.Matchers.contains +import static org.hamcrest.Matchers.containsString +import static org.hamcrest.Matchers.instanceOf +import static org.hamcrest.Matchers.is +import static org.hamcrest.Matchers.not +import static org.junit.Assert.assertThat +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.spy; -import org.junit.* +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class S3BackendPluginTest { diff --git a/test/SemanticVersionTest.groovy b/test/SemanticVersionTest.groovy index e0491c5c..5701fa7d 100644 --- a/test/SemanticVersionTest.groovy +++ b/test/SemanticVersionTest.groovy @@ -1,8 +1,8 @@ +import static org.junit.Assert.assertEquals + import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized -import static org.junit.Assert.* - @RunWith(Parameterized.class) class SemanticVersionTest { @@ -16,10 +16,14 @@ class SemanticVersionTest { @Test void sortsCorrectly() { - List unsorted = SORTED.clone().collect({v -> new SemanticVersion(v)}) - Collections.shuffle(unsorted) - def result = unsorted.sort().collect({sv -> sv.version}) - assertEquals(SORTED,result) + List versions = SORTED.clone().collect { v -> new SemanticVersion(v) } + // Randomize + Collections.shuffle(versions) + // Then sort + versions.sort() + + def result = versions.collect { sv -> sv.version } + assertEquals(SORTED, result) } static SORTED = [ @@ -30,22 +34,22 @@ class SemanticVersionTest { '0.1.0.2', '0.1.0.10', '0.1.0.23', - '0.2', - '0.2.0.3.1', + '0.2', + '0.2.0.3.1', '0.2.0.4', - '1.0RC1', - '1.0RC2', - '1.0', - '1.0.1.2', - '1.0.2', + '1.0RC1', + '1.0RC2', + '1.0', + '1.0.1.2', + '1.0.2', '1.2.2.3', - '1.2.3', - '1.5.2_04', - '1.5.2_05', - '1.5.2_10', + '1.2.3', + '1.5.2_04', + '1.5.2_05', + '1.5.2_10', '1.6.0_01', - '2.0', - '2.0.0_02', + '2.0', + '2.0.0_02', '3.1' ] } diff --git a/test/TerraformApplyCommandTest.groovy b/test/TerraformApplyCommandTest.groovy index b93bbc61..acafaff8 100644 --- a/test/TerraformApplyCommandTest.groovy +++ b/test/TerraformApplyCommandTest.groovy @@ -1,15 +1,17 @@ -import static org.junit.Assert.* - -import org.junit.* +import static org.hamcrest.Matchers.containsString +import static org.hamcrest.Matchers.endsWith +import static org.hamcrest.Matchers.not +import static org.hamcrest.Matchers.startsWith +import static org.junit.Assert.assertThat +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.times +import static org.mockito.Mockito.verify + +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.hamcrest.Matchers.* -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.times; - - @RunWith(HierarchicalContextRunner.class) class TerraformApplyCommandTest { public class WithInput { diff --git a/test/TerraformDirectoryPluginTest.groovy b/test/TerraformDirectoryPluginTest.groovy index c858b044..d154c87e 100644 --- a/test/TerraformDirectoryPluginTest.groovy +++ b/test/TerraformDirectoryPluginTest.groovy @@ -1,11 +1,12 @@ -import static org.junit.Assert.* +import static org.hamcrest.Matchers.containsString +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.junit.Assert.assertThat -import org.junit.* +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.mock; -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class TerraformDirectoryPluginTest { diff --git a/test/TerraformEnvironmentStageTest.groovy b/test/TerraformEnvironmentStageTest.groovy index 1167c612..6cf87685 100644 --- a/test/TerraformEnvironmentStageTest.groovy +++ b/test/TerraformEnvironmentStageTest.groovy @@ -1,13 +1,17 @@ -import static org.junit.Assert.* - -import org.junit.* +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.is +import static org.hamcrest.Matchers.isA +import static org.junit.Assert.assertEquals +import static org.junit.Assert.assertThat +import static org.junit.Assert.assertTrue + +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.hamcrest.Matchers.* - @RunWith(HierarchicalContextRunner.class) class TerraformEnvironmentStageTest { @After @@ -60,7 +64,16 @@ class TerraformEnvironmentStageTest { @Test void doesNotAddPluginToOtherInstances() { + def modifiedStage = new TerraformEnvironmentStage('modified') + def unmodifiedStage = new TerraformEnvironmentStage('unmodified') + + def pluginsBefore = unmodifiedStage.getAllPlugins() + + modifiedStage.withEnv('somekey', 'somevalue') + + def pluginsAfter = unmodifiedStage.getAllPlugins() + assertEquals(pluginsBefore, pluginsAfter) } @Test diff --git a/test/TerraformInitCommandTest.groovy b/test/TerraformInitCommandTest.groovy index 4a54be3e..7d482c1c 100644 --- a/test/TerraformInitCommandTest.groovy +++ b/test/TerraformInitCommandTest.groovy @@ -1,14 +1,15 @@ -import static org.junit.Assert.* - -import org.junit.* -import org.junit.runner.RunWith -import de.bechte.junit.runners.context.HierarchicalContextRunner - -import static org.hamcrest.Matchers.* +import static org.hamcrest.Matchers.containsString +import static org.hamcrest.Matchers.endsWith +import static org.hamcrest.Matchers.not +import static org.junit.Assert.assertThat import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.times; +import org.junit.After +import org.junit.Test +import org.junit.runner.RunWith +import de.bechte.junit.runners.context.HierarchicalContextRunner @RunWith(HierarchicalContextRunner.class) class TerraformInitCommandTest { diff --git a/test/TerraformPlanCommandTest.groovy b/test/TerraformPlanCommandTest.groovy index 8531412e..33c29892 100644 --- a/test/TerraformPlanCommandTest.groovy +++ b/test/TerraformPlanCommandTest.groovy @@ -1,14 +1,16 @@ -import static org.junit.Assert.* - -import org.junit.* -import org.junit.runner.RunWith -import de.bechte.junit.runners.context.HierarchicalContextRunner - -import static org.hamcrest.Matchers.* +import static org.hamcrest.Matchers.containsString +import static org.hamcrest.Matchers.endsWith +import static org.hamcrest.Matchers.not +import static org.hamcrest.Matchers.startsWith +import static org.junit.Assert.assertThat import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.times; +import org.junit.After +import org.junit.Test +import org.junit.runner.RunWith +import de.bechte.junit.runners.context.HierarchicalContextRunner @RunWith(HierarchicalContextRunner.class) class TerraformPlanCommandTest { @@ -86,7 +88,6 @@ class TerraformPlanCommandTest { } } - public class Plugins { @After void resetPlugins() { diff --git a/test/TerraformPluginTest.groovy b/test/TerraformPluginTest.groovy index a5797ea4..30d44c07 100644 --- a/test/TerraformPluginTest.groovy +++ b/test/TerraformPluginTest.groovy @@ -1,15 +1,13 @@ -import org.junit.* -import org.junit.runner.RunWith -import de.bechte.junit.runners.context.HierarchicalContextRunner - -import static org.hamcrest.Matchers.* -import static org.junit.Assert.* -import static org.mockito.Mockito.mock; +import static org.hamcrest.Matchers.instanceOf +import static org.junit.Assert.assertEquals +import static org.junit.Assert.assertThat import static org.mockito.Mockito.spy -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.doReturn; -import static org.mockito.Matchers.* + +import org.junit.After +import org.junit.Test +import org.junit.runner.RunWith +import de.bechte.junit.runners.context.HierarchicalContextRunner @RunWith(HierarchicalContextRunner.class) class TerraformPluginTest { diff --git a/test/TerraformPluginVersion11Test.groovy b/test/TerraformPluginVersion11Test.groovy index e63a983d..e87fb367 100644 --- a/test/TerraformPluginVersion11Test.groovy +++ b/test/TerraformPluginVersion11Test.groovy @@ -1,14 +1,9 @@ -import org.junit.* -import org.junit.runner.RunWith -import de.bechte.junit.runners.context.HierarchicalContextRunner - -import static org.hamcrest.Matchers.* -import static org.junit.Assert.* -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Matchers.* + +import org.junit.Test +import org.junit.runner.RunWith +import de.bechte.junit.runners.context.HierarchicalContextRunner @RunWith(HierarchicalContextRunner.class) class TerraformPluginVersion11Test { diff --git a/test/TerraformPluginVersion12Test.groovy b/test/TerraformPluginVersion12Test.groovy index 807171c0..f01717ec 100644 --- a/test/TerraformPluginVersion12Test.groovy +++ b/test/TerraformPluginVersion12Test.groovy @@ -1,14 +1,13 @@ -import org.junit.* -import org.junit.runner.RunWith -import de.bechte.junit.runners.context.HierarchicalContextRunner - -import static org.hamcrest.Matchers.* -import static org.junit.Assert.* -import static org.mockito.Mockito.mock; +import static org.hamcrest.Matchers.containsString +import static org.junit.Assert.assertThat +import static org.mockito.Matchers.any +import static org.mockito.Matchers.eq import static org.mockito.Mockito.spy -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Matchers.* + +import org.junit.Test +import org.junit.runner.RunWith +import de.bechte.junit.runners.context.HierarchicalContextRunner @RunWith(HierarchicalContextRunner.class) class TerraformPluginVersion12Test { diff --git a/test/TerraformValidateCommandTest.groovy b/test/TerraformValidateCommandTest.groovy index c888a8a1..89ee0301 100644 --- a/test/TerraformValidateCommandTest.groovy +++ b/test/TerraformValidateCommandTest.groovy @@ -1,14 +1,14 @@ -import static org.junit.Assert.* - -import org.junit.* -import org.junit.runner.RunWith -import de.bechte.junit.runners.context.HierarchicalContextRunner - -import static org.hamcrest.Matchers.* +import static org.junit.Assert.assertThat +import static org.hamcrest.Matchers.endsWith +import static org.hamcrest.Matchers.startsWith import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.times; +import org.junit.After +import org.junit.Test +import org.junit.runner.RunWith +import de.bechte.junit.runners.context.HierarchicalContextRunner @RunWith(HierarchicalContextRunner.class) class TerraformValidateCommandTest { diff --git a/test/TfvarsFilesPluginTest.groovy b/test/TfvarsFilesPluginTest.groovy index 838b7ab0..b11fca28 100644 --- a/test/TfvarsFilesPluginTest.groovy +++ b/test/TfvarsFilesPluginTest.groovy @@ -1,9 +1,3 @@ -import de.bechte.junit.runners.context.HierarchicalContextRunner -import org.junit.After -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith - import static org.hamcrest.Matchers.containsString import static org.hamcrest.Matchers.equalTo import static org.hamcrest.Matchers.hasItem @@ -11,6 +5,11 @@ import static org.hamcrest.Matchers.instanceOf import static org.hamcrest.Matchers.not import static org.junit.Assert.assertThat +import de.bechte.junit.runners.context.HierarchicalContextRunner +import org.junit.After +import org.junit.Test +import org.junit.runner.RunWith + @RunWith(HierarchicalContextRunner.class) class TfvarsFilesPluginTest { @@ -44,7 +43,6 @@ class TfvarsFilesPluginTest { TfvarsFilesPlugin.directory = '.' } - class Init { @After void resetPlugins() { diff --git a/test/WithAwsPluginTest.groovy b/test/WithAwsPluginTest.groovy index 46edbb44..cb4b8f72 100644 --- a/test/WithAwsPluginTest.groovy +++ b/test/WithAwsPluginTest.groovy @@ -1,11 +1,15 @@ -import static org.junit.Assert.* +import static org.hamcrest.Matchers.hasItem +import static org.hamcrest.Matchers.instanceOf +import static org.hamcrest.Matchers.is +import static org.junit.Assert.assertThat +import static org.junit.Assert.assertTrue +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.mock; -import org.junit.* +import org.junit.After +import org.junit.Test import org.junit.runner.RunWith import de.bechte.junit.runners.context.HierarchicalContextRunner -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.mock; -import static org.hamcrest.Matchers.* @RunWith(HierarchicalContextRunner.class) class WithAwsPluginTest { @@ -140,4 +144,3 @@ class WithAwsPluginTest { } } - From ee269602c58610202f5d34d868588c7dc535ac9c Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Wed, 5 Feb 2020 19:31:54 -0500 Subject: [PATCH 2/2] Fix broken terraform version detection --- src/TerraformPlugin.groovy | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/TerraformPlugin.groovy b/src/TerraformPlugin.groovy index 67efd27e..af2db8a1 100644 --- a/src/TerraformPlugin.groovy +++ b/src/TerraformPlugin.groovy @@ -35,7 +35,10 @@ class TerraformPlugin implements TerraformValidateCommandPlugin, TerraformValida } public TerraformPluginVersion strategyFor(String version) { - if (new SemanticVersion(version) >= new SemanticVersion('0.12.0')) { + // if (new SemanticVersion(version) >= new SemanticVersion('0.12.0')) should be used + // here. Unit tests pass with the above, but running Jenkinsfile in a pipeline context + // does not. Debug statements show that the above will return 0 when it should return 'true'. + if ((new SemanticVersion(version) <=> new SemanticVersion('0.12.0')) >= 0) { return new TerraformPluginVersion12() }