2016-04-12 03:09:59 +02:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
2016-11-22 00:13:15 +01:00
|
|
|
"fmt"
|
2016-04-12 03:09:59 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStateAdd(t *testing.T) {
|
2016-11-22 00:13:15 +01:00
|
|
|
cases := []struct {
|
|
|
|
Name string
|
2016-04-12 03:09:59 +02:00
|
|
|
Err bool
|
2016-04-12 18:46:16 +02:00
|
|
|
From, To string
|
2016-04-12 03:09:59 +02:00
|
|
|
Value interface{}
|
|
|
|
One, Two *State
|
|
|
|
}{
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ModuleState => Module Addr (new)",
|
2016-04-12 03:09:59 +02:00
|
|
|
false,
|
2016-04-12 18:46:16 +02:00
|
|
|
"",
|
2016-04-12 03:09:59 +02:00
|
|
|
"module.foo",
|
|
|
|
&ModuleState{
|
|
|
|
Path: rootModulePath,
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
"test_instance.bar": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "foo"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
"test_instance.bar": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
2016-04-13 00:21:10 +02:00
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ModuleState => Nested Module Addr (new)",
|
2016-04-13 00:21:10 +02:00
|
|
|
false,
|
|
|
|
"",
|
|
|
|
"module.foo.module.bar",
|
|
|
|
&ModuleState{
|
|
|
|
Path: rootModulePath,
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
"test_instance.bar": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "foo", "bar"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
"test_instance.bar": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
2016-04-12 03:09:59 +02:00
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ModuleState w/ outputs and deps => Module Addr (new)",
|
2016-04-12 03:09:59 +02:00
|
|
|
false,
|
2016-04-12 18:46:16 +02:00
|
|
|
"",
|
2016-04-12 03:09:59 +02:00
|
|
|
"module.foo",
|
|
|
|
&ModuleState{
|
|
|
|
Path: rootModulePath,
|
2016-05-12 02:05:02 +02:00
|
|
|
Outputs: map[string]*OutputState{
|
|
|
|
"foo": &OutputState{
|
|
|
|
Type: "string",
|
|
|
|
Sensitive: false,
|
|
|
|
Value: "bar",
|
|
|
|
},
|
2016-04-12 03:09:59 +02:00
|
|
|
},
|
|
|
|
Dependencies: []string{"foo"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
"test_instance.bar": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "foo"},
|
2016-05-12 02:05:02 +02:00
|
|
|
Outputs: map[string]*OutputState{
|
|
|
|
"foo": &OutputState{
|
|
|
|
Type: "string",
|
|
|
|
Sensitive: false,
|
|
|
|
Value: "bar",
|
|
|
|
},
|
2016-04-12 03:09:59 +02:00
|
|
|
},
|
|
|
|
Dependencies: []string{"foo"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
"test_instance.bar": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ModuleState => Module Addr (existing)",
|
2016-04-12 03:09:59 +02:00
|
|
|
true,
|
2016-04-12 18:46:16 +02:00
|
|
|
"",
|
2016-04-12 03:09:59 +02:00
|
|
|
"module.foo",
|
|
|
|
&ModuleState{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "foo"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.baz": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
2016-04-12 03:22:11 +02:00
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ModuleState with children => Module Addr (new)",
|
2016-08-18 21:05:42 +02:00
|
|
|
false,
|
|
|
|
"module.foo",
|
|
|
|
"module.bar",
|
|
|
|
|
|
|
|
[]*ModuleState{
|
|
|
|
&ModuleState{
|
2016-08-18 23:39:07 +02:00
|
|
|
Path: []string{"root", "foo"},
|
2016-08-18 21:05:42 +02:00
|
|
|
Resources: map[string]*ResourceState{},
|
|
|
|
},
|
|
|
|
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "foo", "child1"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "foo", "child2"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// Should be ignored
|
|
|
|
&ModuleState{
|
2016-08-18 23:13:53 +02:00
|
|
|
Path: []string{"root", "baz", "child2"},
|
2016-08-18 21:05:42 +02:00
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
2016-08-18 23:13:53 +02:00
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "bar"},
|
|
|
|
Resources: map[string]*ResourceState{},
|
|
|
|
},
|
|
|
|
|
2016-08-18 21:05:42 +02:00
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "bar", "child1"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "bar", "child2"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"test_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ResourceState => Resource Addr (new)",
|
2016-04-12 03:22:11 +02:00
|
|
|
false,
|
2016-04-12 18:46:16 +02:00
|
|
|
"aws_instance.bar",
|
2016-04-12 03:22:11 +02:00
|
|
|
"aws_instance.foo",
|
|
|
|
&ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-04-12 03:26:15 +02:00
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ResourceState w/ deps, provider => Resource Addr (new)",
|
2016-04-12 03:29:51 +02:00
|
|
|
false,
|
2016-04-12 18:46:16 +02:00
|
|
|
"aws_instance.bar",
|
2016-04-12 03:29:51 +02:00
|
|
|
"aws_instance.foo",
|
|
|
|
&ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Provider: "foo",
|
|
|
|
Dependencies: []string{"bar"},
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Provider: "foo",
|
|
|
|
Dependencies: []string{"bar"},
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ResourceState tainted => Resource Addr (new)",
|
2016-04-12 03:41:48 +02:00
|
|
|
false,
|
2016-04-12 18:46:16 +02:00
|
|
|
"aws_instance.bar",
|
2016-04-12 03:41:48 +02:00
|
|
|
"aws_instance.foo",
|
|
|
|
&ResourceState{
|
|
|
|
Type: "test_instance",
|
2016-05-23 12:23:48 +02:00
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Tainted: true,
|
2016-04-12 03:41:48 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.foo": &ResourceState{
|
2016-05-23 12:23:48 +02:00
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Tainted: true,
|
2016-04-12 03:41:48 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ResourceState with count unspecified => Resource Addr (new)",
|
2016-08-19 17:46:52 +02:00
|
|
|
false,
|
|
|
|
"aws_instance.bar",
|
|
|
|
"aws_instance.foo",
|
|
|
|
[]*ResourceState{
|
|
|
|
&ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.foo.0": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
"aws_instance.foo.1": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ResourceState with count unspecified => Resource Addr (new with count)",
|
2016-08-19 17:51:31 +02:00
|
|
|
true,
|
|
|
|
"aws_instance.bar",
|
|
|
|
"aws_instance.foo[0]",
|
|
|
|
[]*ResourceState{
|
|
|
|
&ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ResourceState with single count unspecified => Resource Addr (new with count)",
|
2016-08-19 17:54:53 +02:00
|
|
|
false,
|
|
|
|
"aws_instance.bar",
|
|
|
|
"aws_instance.foo[0]",
|
|
|
|
[]*ResourceState{
|
|
|
|
&ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.foo.0": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ResourceState => Resource Addr (new with count)",
|
2016-08-19 17:54:53 +02:00
|
|
|
false,
|
|
|
|
"aws_instance.bar",
|
|
|
|
"aws_instance.foo[0]",
|
|
|
|
&ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.foo.0": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ResourceState => Resource Addr (existing)",
|
2016-04-12 03:26:15 +02:00
|
|
|
true,
|
2016-04-12 18:46:16 +02:00
|
|
|
"aws_instance.bar",
|
2016-04-12 03:26:15 +02:00
|
|
|
"aws_instance.foo",
|
|
|
|
&ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.foo": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
2016-04-12 18:46:16 +02:00
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"ResourceState => Module (new)",
|
2016-04-12 18:46:16 +02:00
|
|
|
false,
|
|
|
|
"aws_instance.bar",
|
|
|
|
"module.foo",
|
|
|
|
&ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "foo"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.bar": &ResourceState{
|
|
|
|
Type: "test_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-04-12 18:51:43 +02:00
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"InstanceState => Resource (new)",
|
2016-04-12 18:51:43 +02:00
|
|
|
false,
|
|
|
|
"aws_instance.bar.primary",
|
|
|
|
"aws_instance.baz",
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.baz": &ResourceState{
|
|
|
|
Type: "aws_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-04-12 18:55:17 +02:00
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
{
|
|
|
|
"InstanceState => Module (new)",
|
2016-04-12 18:55:17 +02:00
|
|
|
false,
|
|
|
|
"aws_instance.bar.primary",
|
|
|
|
"module.foo",
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
|
|
|
|
&State{},
|
|
|
|
&State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "foo"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.bar": &ResourceState{
|
|
|
|
Type: "aws_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-04-12 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2016-11-22 00:13:15 +01:00
|
|
|
for i, tc := range cases {
|
|
|
|
t.Run(fmt.Sprintf("%d-%s", i, tc.Name), func(t *testing.T) {
|
|
|
|
// Make sure they're both initialized as normal
|
|
|
|
tc.One.init()
|
|
|
|
if tc.Two != nil {
|
|
|
|
tc.Two.init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the value
|
|
|
|
err := tc.One.Add(tc.From, tc.To, tc.Value)
|
|
|
|
if (err != nil) != tc.Err {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if tc.Err {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prune them both to be sure
|
|
|
|
tc.One.prune()
|
|
|
|
tc.Two.prune()
|
|
|
|
|
|
|
|
// Verify equality
|
|
|
|
if !tc.One.Equal(tc.Two) {
|
|
|
|
//t.Fatalf("Bad: %s\n\n%#v\n\n%#v", k, tc.One, tc.Two)
|
|
|
|
t.Fatalf("Bad: \n\n%s\n\n%s", tc.One.String(), tc.Two.String())
|
|
|
|
}
|
|
|
|
})
|
2016-04-12 03:09:59 +02:00
|
|
|
}
|
|
|
|
}
|