From dcc3eb301149b2c6e433799e97dd26033989158f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 13 Sep 2016 17:55:01 -0700 Subject: [PATCH] terraform: test for ResourceAddress.stateId() --- terraform/resource_address.go | 1 - terraform/resource_address_test.go | 49 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/terraform/resource_address.go b/terraform/resource_address.go index 13c7170d5..643833ff3 100644 --- a/terraform/resource_address.go +++ b/terraform/resource_address.go @@ -88,7 +88,6 @@ func (r *ResourceAddress) String() string { // stateId returns the ID that this resource should be entered with // in the state. This is also used for diffs. In the future, we'd like to // move away from this string field so I don't export this. -// TODO: test func (r *ResourceAddress) stateId() string { result := fmt.Sprintf("%s.%s", r.Type, r.Name) switch r.Mode { diff --git a/terraform/resource_address_test.go b/terraform/resource_address_test.go index ac0720e4e..02d9e82e5 100644 --- a/terraform/resource_address_test.go +++ b/terraform/resource_address_test.go @@ -521,3 +521,52 @@ func TestResourceAddressEquals(t *testing.T) { } } } + +func TestResourceAddressStateId(t *testing.T) { + cases := map[string]struct { + Input *ResourceAddress + Expected string + }{ + "basic resource": { + &ResourceAddress{ + Mode: config.ManagedResourceMode, + Type: "aws_instance", + Name: "foo", + InstanceType: TypePrimary, + Index: -1, + }, + "aws_instance.foo", + }, + + "basic resource ignores count": { + &ResourceAddress{ + Mode: config.ManagedResourceMode, + Type: "aws_instance", + Name: "foo", + InstanceType: TypePrimary, + Index: 2, + }, + "aws_instance.foo", + }, + + "data resource": { + &ResourceAddress{ + Mode: config.DataResourceMode, + Type: "aws_instance", + Name: "foo", + InstanceType: TypePrimary, + Index: -1, + }, + "data.aws_instance.foo", + }, + } + + for tn, tc := range cases { + t.Run(tn, func(t *testing.T) { + actual := tc.Input.stateId() + if actual != tc.Expected { + t.Fatalf("bad: %q\n\nexpected: %s\n\ngot: %s", tn, tc.Expected, actual) + } + }) + } +}