core: Fix tests for TestPlanGraphBuilder

Previously this was just stubbing out provider types, but we now need to
include schema for each of the providers and resource types the tests
use in order for the references to be properly detected.

The test fixtures are adjusted slightly here so we can use the
simpleTestSchema as the schema for all of the different blocks in these
tests. The relationships between the resources are still preserved, but
the attributes are renamed to comply with this schema.
This commit is contained in:
Martin Atkins 2018-05-10 09:56:32 -07:00
parent 168354c2e8
commit f7b8e3b8be
5 changed files with 42 additions and 36 deletions

View File

@ -1,11 +1,11 @@
package terraform
import (
"fmt"
"strings"
"testing"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/config/configschema"
)
func TestPlanGraphBuilder_impl(t *testing.T) {
@ -17,12 +17,24 @@ func TestPlanGraphBuilder(t *testing.T) {
Config: testModule(t, "graph-builder-plan-basic"),
Components: &basicComponentFactory{
providers: map[string]ResourceProviderFactory{
"aws": func() (ResourceProvider, error) {
return nil, fmt.Errorf("not implemented")
},
"openstack": func() (ResourceProvider, error) {
return nil, fmt.Errorf("not implemented")
},
"aws": ResourceProviderFactoryFixed(&MockResourceProvider{
GetSchemaReturn: &ProviderSchema{
Provider: simpleTestSchema(),
ResourceTypes: map[string]*configschema.Block{
"aws_security_group": simpleTestSchema(),
"aws_instance": simpleTestSchema(),
"aws_load_balancer": simpleTestSchema(),
},
},
}),
"openstack": ResourceProviderFactoryFixed(&MockResourceProvider{
GetSchemaReturn: &ProviderSchema{
Provider: simpleTestSchema(),
ResourceTypes: map[string]*configschema.Block{
"openstack_floating_ip": simpleTestSchema(),
},
},
}),
},
},
DisableReduce: true,
@ -46,17 +58,8 @@ func TestPlanGraphBuilder(t *testing.T) {
func TestPlanGraphBuilder_targetModule(t *testing.T) {
b := &PlanGraphBuilder{
Config: testModule(t, "graph-builder-plan-target-module-provider"),
Components: &basicComponentFactory{
providers: map[string]ResourceProviderFactory{
"null": func() (ResourceProvider, error) {
return nil, fmt.Errorf("not implemented")
},
"openstack": func() (ResourceProvider, error) {
return nil, fmt.Errorf("not implemented")
},
},
},
Config: testModule(t, "graph-builder-plan-target-module-provider"),
Components: simpleMockComponentFactory(),
Targets: []addrs.Targetable{
addrs.RootModuleInstance.Child("child2", addrs.NoKey),
},
@ -69,8 +72,8 @@ func TestPlanGraphBuilder_targetModule(t *testing.T) {
t.Logf("Graph: %s", g.String())
testGraphNotContains(t, g, "module.child1.provider.null")
testGraphNotContains(t, g, "module.child1.null_resource.foo")
testGraphNotContains(t, g, "module.child1.provider.test")
testGraphNotContains(t, g, "module.child1.test_object.foo")
}
const testPlanGraphBuilderStr = `

View File

@ -1,10 +1,10 @@
variable "foo" {
default = "bar"
description = "bar"
default = "bar"
description = "bar"
}
provider "aws" {
foo = "${openstack_floating_ip.random.value}"
test_string = "${openstack_floating_ip.random.test_string}"
}
resource "openstack_floating_ip" "random" {}
@ -12,19 +12,20 @@ resource "openstack_floating_ip" "random" {}
resource "aws_security_group" "firewall" {}
resource "aws_instance" "web" {
ami = "${var.foo}"
security_groups = [
"foo",
"${aws_security_group.firewall.foo}"
]
test_string = var.foo
test_list = [
"foo",
aws_security_group.firewall.test_string,
]
}
resource "aws_load_balancer" "weblb" {
members = "${aws_instance.web.id_list}"
test_list = aws_instance.web.test_list
}
locals {
instance_id = "${aws_instance.web.id}"
instance_id = "${aws_instance.web.test_string}"
}
output "instance_id" {

View File

@ -1,7 +1,7 @@
variable "key" {}
provider "null" {
key = "${var.key}"
provider "test" {
test_string = "${var.key}"
}
resource "null_resource" "foo" {}
resource "test_object" "foo" {}

View File

@ -1,7 +1,7 @@
variable "key" {}
provider "null" {
key = "${var.key}"
provider "test" {
test_string = "${var.key}"
}
resource "null_resource" "foo" {}
resource "test_object" "foo" {}

View File

@ -1,7 +1,9 @@
module "child1" {
source = "./child1"
key = "!"
}
module "child2" {
source = "./child2"
key = "!"
}