From 72ae652347379796b148ab118ea420912f72f02d Mon Sep 17 00:00:00 2001 From: nritholtz Date: Sun, 7 Apr 2019 12:58:16 -0400 Subject: [PATCH] Added additional testing --- main_test.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index d77d3c0..f96ff92 100644 --- a/main_test.go +++ b/main_test.go @@ -38,13 +38,43 @@ func TestTerraformWithTerrafilePath(t *testing.T) { } { assert.Contains(t, testcli.Stdout(), output) } - // Assert files exist + // Assert folder exist for _, moduleName := range []string{ "tf-aws-vpc", "tf-aws-vpc-experimental", } { assert.DirExists(t, path.Join(workingDirectory, "vendor/modules", moduleName)) } + + // Assert files exist + for _, moduleName := range []string{ + "tf-aws-vpc/main.tf", + "tf-aws-vpc-experimental/main.tf", + } { + assert.FileExists(t, path.Join(workingDirectory, "vendor/modules", moduleName)) + } + + // Assert checked out correct version + for moduleName, cloneOptions := range map[string]map[string]string{ + "tf-aws-vpc": map[string]string{ + "repository": "git@github.com:terraform-aws-modules/terraform-aws-vpc", + "version": "v1.46.0", + }, + "tf-aws-vpc-experimental": map[string]string{ + "repository": "git@github.com:terraform-aws-modules/terraform-aws-vpc", + "version": "master", + }, + } { + testModuleLocation := path.Join(workingDirectory, "vendor/modules", moduleName+"__test") + testcli.Run("git", "clone", "-b", cloneOptions["version"], cloneOptions["repository"], testModuleLocation) + if !testcli.Success() { + t.Fatalf("Expected to succeed, but failed: %q with message: %q", testcli.Error(), testcli.Stderr()) + } + testcli.Run("diff", "--exclude=.git", "-r", path.Join(workingDirectory, "vendor/modules", moduleName), testModuleLocation) + if !testcli.Success() { + t.Fatalf("File difference found for %q, with failure: %q with message: %q", moduleName, testcli.Error(), testcli.Stderr()) + } + } } func setup(t *testing.T) (current string, back func()) {