configs/configload: installer tests inspect their result

Previously we were just loading the module and asserting no diagnostics,
but that is not really good enough since if we install modules incorrectly
it's possible that we are still able to load an empty configuration
successfully.

Now we'll do some basic inspecetion of the module tree that results from
loading what we installed, to ensure that all of the expected modules
are present at the right locations in the tree.
This commit is contained in:
Martin Atkins 2018-02-15 09:23:07 -08:00
parent d859bacbdd
commit ea868026b8
6 changed files with 92 additions and 3 deletions

View File

@ -3,9 +3,11 @@ package configload
import (
"os"
"path/filepath"
"strings"
"testing"
version "github.com/hashicorp/go-version"
"github.com/hashicorp/terraform/configs"
)
func TestLoaderInstallModules_local(t *testing.T) {
@ -39,8 +41,25 @@ func TestLoaderInstallModules_local(t *testing.T) {
// Make sure the configuration is loadable now.
// (This ensures that correct information is recorded in the manifest.)
_, loadDiags := loader.LoadConfig(".")
config, loadDiags := loader.LoadConfig(".")
assertNoDiagnostics(t, loadDiags)
wantTraces := map[string]string{
"": "in root module",
"child_a": "in child_a module",
"child_a.child_b": "in child_b module",
}
gotTraces := map[string]string{}
config.DeepEach(func(c *configs.Config) {
path := strings.Join(c.Path, ".")
if c.Module.Variables["v"] == nil {
gotTraces[path] = "<missing>"
return
}
varDesc := c.Module.Variables["v"].Description
gotTraces[path] = varDesc
})
assertResultDeepEqual(t, gotTraces, wantTraces)
}
func TestLoaderInstallModules_registry(t *testing.T) {
@ -136,8 +155,30 @@ func TestLoaderInstallModules_registry(t *testing.T) {
// Make sure the configuration is loadable now.
// (This ensures that correct information is recorded in the manifest.)
_, loadDiags := loader.LoadConfig(".")
config, loadDiags := loader.LoadConfig(".")
assertNoDiagnostics(t, loadDiags)
wantTraces := map[string]string{
"": "in local caller for registry-modules",
"acctest_root": "in root module",
"acctest_root.child_a": "in child_a module",
"acctest_root.child_a.child_b": "in child_b module",
"acctest_child_a": "in child_a module",
"acctest_child_a.child_b": "in child_b module",
"acctest_child_b": "in child_b module",
}
gotTraces := map[string]string{}
config.DeepEach(func(c *configs.Config) {
path := strings.Join(c.Path, ".")
if c.Module.Variables["v"] == nil {
gotTraces[path] = "<missing>"
return
}
varDesc := c.Module.Variables["v"].Description
gotTraces[path] = varDesc
})
assertResultDeepEqual(t, gotTraces, wantTraces)
}
func TestLoaderInstallModules_goGetter(t *testing.T) {
@ -225,8 +266,30 @@ func TestLoaderInstallModules_goGetter(t *testing.T) {
// Make sure the configuration is loadable now.
// (This ensures that correct information is recorded in the manifest.)
_, loadDiags := loader.LoadConfig(".")
config, loadDiags := loader.LoadConfig(".")
assertNoDiagnostics(t, loadDiags)
wantTraces := map[string]string{
"": "in local caller for go-getter-modules",
"acctest_root": "in root module",
"acctest_root.child_a": "in child_a module",
"acctest_root.child_a.child_b": "in child_b module",
"acctest_child_a": "in child_a module",
"acctest_child_a.child_b": "in child_b module",
"acctest_child_b": "in child_b module",
}
gotTraces := map[string]string{}
config.DeepEach(func(c *configs.Config) {
path := strings.Join(c.Path, ".")
if c.Module.Variables["v"] == nil {
gotTraces[path] = "<missing>"
return
}
varDesc := c.Module.Variables["v"].Description
gotTraces[path] = varDesc
})
assertResultDeepEqual(t, gotTraces, wantTraces)
}
type testInstallHooks struct {

View File

@ -3,6 +3,11 @@
# ...and expects its v0.0.1 tag to be pointing at the following commit:
# d676ab2559d4e0621d59e3c3c4cbb33958ac4608
variable "v" {
description = "in local caller for go-getter-modules"
default = ""
}
module "acctest_root" {
source = "github.com/hashicorp/terraform-aws-module-installer-acctest?ref=v0.0.1"
}

View File

@ -1,4 +1,9 @@
variable "v" {
description = "in child_a module"
default = ""
}
module "child_b" {
source = "./child_b"
}

View File

@ -1,4 +1,9 @@
variable "v" {
description = "in child_b module"
default = ""
}
output "hello" {
value = "Hello from child_b!"
}

View File

@ -1,4 +1,9 @@
variable "v" {
description = "in root module"
default = ""
}
module "child_a" {
source = "./child_a"
}

View File

@ -11,6 +11,12 @@
# 853d03855b3290a3ca491d4c3a7684572dd42237
# (this particular assumption is encoded in the tests that use this fixture)
variable "v" {
description = "in local caller for registry-modules"
default = ""
}
module "acctest_root" {
source = "hashicorp/module-installer-acctest/aws"
version = "0.0.1"