config: allow tests to force using the HCL2 loader

Currently the default for tests is to use the old HCL loader, but we need
to be able to test aspects of the new loader as we work through the
experimental phase. This new function testConfigHCL2 is the same as
testConfig except that it forces the use of HCL2 even if the opt-in
comment isn't present, thus allowing us to implement tests that ensure
that the exact same file works in both the old and new cases.

Once the HCL2 loader becomes the default this function will be removed
and callers will start calling into the normal testConfig function.
This commit is contained in:
Martin Atkins 2017-09-28 17:03:54 -07:00
parent d91327eaa0
commit 71e68f06c4
1 changed files with 17 additions and 0 deletions

View File

@ -699,6 +699,23 @@ func testConfig(t *testing.T, name string) *Config {
return c
}
// testConfigHCL loads a config, forcing it to be processed with the HCL2
// loader even if it doesn't explicitly opt in to the HCL2 experiment.
func testConfigHCL2(t *testing.T, name string) *Config {
t.Helper()
cer, _, err := globalHCL2Loader.loadFile(filepath.Join(fixtureDir, name, "main.tf"))
if err != nil {
t.Fatalf("failed to load %s: %s", name, err)
}
cfg, err := cer.Config()
if err != nil {
t.Fatalf("failed to decode %s: %s", name, err)
}
return cfg
}
func TestConfigDataCount(t *testing.T) {
c := testConfig(t, "data-count")
actual, err := c.Resources[0].Count()