Fix module source expr tests

dbanck/init-graph
Daniel Banck 7 days ago
parent ea9d8cc873
commit 512cf3be2f
No known key found for this signature in database

@ -16,13 +16,6 @@ import (
)
func TestParseConfigResourceFromExpression(t *testing.T) {
mustExpr := func(expr hcl.Expression, diags hcl.Diagnostics) hcl.Expression {
if diags != nil {
panic(diags.Error())
}
return expr
}
tests := []struct {
expr hcl.Expression
expect addrs.ConfigResource
@ -280,3 +273,10 @@ func mustAbsResourceInstanceAddr(str string) addrs.AbsResourceInstance {
}
return addr
}
func mustExpr(expr hcl.Expression, diags hcl.Diagnostics) hcl.Expression {
if diags != nil {
panic(diags.Error())
}
return expr
}

@ -4,18 +4,19 @@
package configs
import (
"io/ioutil"
"os"
"testing"
"github.com/go-test/deep"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/getmodules/moduleaddrs"
)
func TestLoadModuleCall(t *testing.T) {
src, err := ioutil.ReadFile("testdata/invalid-files/module-calls.tf")
src, err := os.ReadFile("testdata/invalid-files/module-calls.tf")
if err != nil {
t.Fatal(err)
}
@ -32,7 +33,11 @@ func TestLoadModuleCall(t *testing.T) {
gotModules := file.ModuleCalls
wantModules := []*ModuleCall{
{
Name: "foo",
Name: "foo",
SourceExpr: mustExpr(hclsyntax.ParseExpression(
[]byte("\"./foo\""), "module-calls.tf",
hcl.Pos{Line: 3, Column: 12, Byte: 27},
)),
SourceAddr: addrs.ModuleSourceLocal("./foo"),
SourceAddrRaw: "./foo",
SourceSet: true,
@ -49,6 +54,10 @@ func TestLoadModuleCall(t *testing.T) {
},
{
Name: "bar",
SourceExpr: mustExpr(hclsyntax.ParseExpression(
[]byte("\"hashicorp/bar/aws\""), "module-calls.tf",
hcl.Pos{Line: 8, Column: 12, Byte: 113},
)),
SourceAddr: addrs.ModuleSourceRegistry{
Package: addrs.ModuleRegistryPackage{
Host: addrs.DefaultModuleRegistryHost,
@ -72,6 +81,10 @@ func TestLoadModuleCall(t *testing.T) {
},
{
Name: "baz",
SourceExpr: mustExpr(hclsyntax.ParseExpression(
[]byte("\"git::https://example.com/\""), "module-calls.tf",
hcl.Pos{Line: 15, Column: 12, Byte: 193},
)),
SourceAddr: addrs.ModuleSourceRemote{
Package: addrs.ModulePackage("git::https://example.com/"),
},

@ -9,6 +9,7 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/zclconf/go-cty/cty"
"github.com/hashicorp/terraform/internal/addrs"
@ -91,7 +92,11 @@ func TestModuleOverrideModule(t *testing.T) {
got := mod.ModuleCalls["example"]
want := &ModuleCall{
Name: "example",
Name: "example",
SourceExpr: mustExpr(hclsyntax.ParseExpression(
[]byte("\"./example2-a_override\""), "testdata/valid-modules/override-module/a_override.tf",
hcl.Pos{Line: 3, Column: 12, Byte: 31},
)),
SourceAddr: addrs.ModuleSourceLocal("./example2-a_override"),
SourceAddrRaw: "./example2-a_override",
SourceAddrRange: hcl.Range{

Loading…
Cancel
Save