-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#57 Adding support for terraform validate command.
- Loading branch information
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,97 @@ | ||
using System.Collections.Generic; | ||
using Cake.Core; | ||
using Cake.Terraform.Validate; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Terraform.Tests | ||
{ | ||
public class TerraformValidateTests | ||
{ | ||
class Fixture : TerraformFixture<TerraformValidateSettings> | ||
{ | ||
public Fixture(PlatformFamily platformFamily = PlatformFamily.Windows) : base(platformFamily) { } | ||
|
||
protected override void RunTool() | ||
{ | ||
ProcessRunner.Process.SetStandardOutput(new List<string> { "default" }); | ||
|
||
var tool = new TerraformValidateRunner(FileSystem, Environment, ProcessRunner, Tools); | ||
|
||
tool.Run(Settings); | ||
} | ||
} | ||
|
||
public class TheExecutable | ||
{ | ||
[Fact] | ||
public void Should_throw_if_terraform_runner_was_not_found() | ||
{ | ||
var fixture = new Fixture(); | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
Assert.IsType<CakeException>(result); | ||
Assert.Equal("Terraform: Could not locate executable.", result.Message); | ||
} | ||
|
||
[Theory] | ||
[InlineData("/bin/tools/terraform/terraform.exe", "/bin/tools/terraform/terraform.exe")] | ||
[InlineData("/bin/tools/terraform/terraform", "/bin/tools/terraform/terraform")] | ||
public void Should_use_terraform_from_tool_path_if_provided(string toolPath, string expected) | ||
{ | ||
var fixture = new Fixture() { Settings = { ToolPath = toolPath } }; | ||
fixture.GivenSettingsToolPathExist(); | ||
|
||
var result = fixture.Run(); | ||
|
||
Assert.Equal(expected, result.Path.FullPath); | ||
} | ||
|
||
[Fact] | ||
public void Should_find_terraform_if_tool_path_not_provided() | ||
{ | ||
var fixture = new Fixture(); | ||
|
||
var result = fixture.Run(); | ||
|
||
Assert.Equal("/Working/tools/terraform.exe", result.Path.FullPath); | ||
} | ||
|
||
[Fact] | ||
public void Should_throw_if_process_has_a_non_zero_exit_code() | ||
{ | ||
var fixture = new Fixture(); | ||
fixture.GivenProcessExitsWithCode(1); | ||
|
||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
Assert.IsType<CakeException>(result); | ||
Assert.Equal("Terraform: Process returned an error (exit code 1).", result.Message); | ||
} | ||
|
||
[Fact] | ||
public void Should_find_linux_executable() | ||
{ | ||
var fixture = new Fixture(PlatformFamily.Linux); | ||
fixture.Environment.Platform.Family = PlatformFamily.Linux; | ||
|
||
|
||
var result = fixture.Run(); | ||
|
||
Assert.Equal("/Working/tools/terraform", result.Path.FullPath); | ||
} | ||
|
||
[Fact] | ||
public void Should_set_workspace_and_list_parameter() | ||
{ | ||
var fixture = new Fixture(); | ||
|
||
var result = fixture.Run(); | ||
|
||
Assert.Contains("validate", result.Args); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Cake.Core; | ||
using Cake.Core.IO; | ||
using Cake.Core.Tooling; | ||
using Cake.Terraform.Init; | ||
|
||
namespace Cake.Terraform.Validate | ||
{ | ||
public class TerraformValidateRunner : TerraformRunner<TerraformValidateSettings> | ||
{ | ||
public TerraformValidateRunner(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IToolLocator tools) | ||
: base(fileSystem, environment, processRunner, tools) | ||
{ | ||
} | ||
|
||
public void Run(TerraformValidateSettings settings) | ||
{ | ||
var builder = new ProcessArgumentBuilder().Append("validate"); | ||
|
||
|
||
Run(settings, builder); | ||
} | ||
} | ||
|
||
public class TerraformValidateSettings : TerraformSettings | ||
{ | ||
} | ||
} |