Skip to content

Commit ac19d97

Browse files
authored
Merge pull request #423 from jleopold28/issue_422
Implement TerraformInitCommandPlugin
2 parents 9b707b4 + 6cc88ef commit ac19d97

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Unreleased
2+
- [Issue #422](https://github.com/manheim/terraform-pipeline/issues/422) TerraformPlugin and TerraformPluginVersion should implement TerraformInitCommandPlugin
23

34
# v5.18
45

src/TerraformPlugin.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
class TerraformPlugin implements TerraformValidateCommandPlugin,
1313
TerraformFormatCommandPlugin,
14+
TerraformInitCommandPlugin,
1415
TerraformPlanCommandPlugin,
1516
TerraformApplyCommandPlugin,
1617
TerraformValidateStagePlugin,
@@ -25,6 +26,7 @@ class TerraformPlugin implements TerraformValidateCommandPlugin,
2526

2627
TerraformValidateCommand.addPlugin(plugin)
2728
TerraformFormatCommand.addPlugin(plugin)
29+
TerraformInitCommand.addPlugin(plugin)
2830
TerraformPlanCommand.addPlugin(plugin)
2931
TerraformApplyCommand.addPlugin(plugin)
3032
TerraformValidateStage.addPlugin(plugin)
@@ -75,6 +77,7 @@ class TerraformPlugin implements TerraformValidateCommandPlugin,
7577

7678
TerraformValidateCommand.reset()
7779
TerraformFormatCommand.reset()
80+
TerraformInitCommand.reset()
7881
TerraformPlanCommand.reset()
7982
TerraformApplyCommand.reset()
8083
TerraformValidateStage.reset()
@@ -90,6 +93,11 @@ class TerraformPlugin implements TerraformValidateCommandPlugin,
9093
applyToCommand(command)
9194
}
9295

96+
@Override
97+
void apply(TerraformInitCommand command) {
98+
applyToCommand(command)
99+
}
100+
93101
@Override
94102
void apply(TerraformPlanCommand command) {
95103
applyToCommand(command)

src/TerraformPluginVersion.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
abstract class TerraformPluginVersion implements TerraformValidateStagePlugin,
22
TerraformValidateCommandPlugin,
3+
TerraformInitCommandPlugin,
34
TerraformPlanCommandPlugin,
45
TerraformApplyCommandPlugin,
56
TerraformFormatCommandPlugin {
@@ -11,6 +12,10 @@ abstract class TerraformPluginVersion implements TerraformValidateStagePlugin,
1112
public void apply(TerraformValidateCommand command) {
1213
}
1314

15+
@Override
16+
public void apply(TerraformInitCommand command) {
17+
}
18+
1419
@Override
1520
public void apply(TerraformPlanCommand command) {
1621
}

test/TerraformPluginTest.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ class TerraformPluginTest {
128128
}
129129
}
130130

131+
@Nested
132+
class ApplyTerraformInitCommand {
133+
@Test
134+
void shouldApplyTheCorrectStrategyToTerraformInitCommand() {
135+
def initCommand = mock(TerraformInitCommand.class)
136+
def strategy = mock(TerraformPluginVersion.class)
137+
def plugin = spy(new TerraformPlugin())
138+
doReturn('someVersion').when(plugin).detectVersion()
139+
doReturn(strategy).when(plugin).strategyFor('someVersion')
140+
141+
plugin.apply(initCommand)
142+
143+
verify(strategy, times(1)).apply(initCommand)
144+
}
145+
}
146+
131147
@Nested
132148
class ApplyTerraformFormatCommand {
133149
@Test

0 commit comments

Comments
 (0)