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