From 241dae7ead06aa48c7427a49c330faade420dcfe Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 2 Nov 2017 15:25:59 -0400 Subject: [PATCH] resintate disabled tests Reinstate the disabled tests that required some sort of inheritance during graph evaluation. --- terraform/context_apply_test.go | 174 ++++++++++++++--------------- terraform/context_validate_test.go | 90 ++++++++------- 2 files changed, 130 insertions(+), 134 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 0f1fd47a6..00ad66523 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -2639,107 +2639,105 @@ module.child: `) } -//// FIXME: how do we handle this one? -//func TestContext2Apply_moduleOrphanProvider(t *testing.T) { -// m := testModule(t, "apply-module-orphan-provider-inherit") -// p := testProvider("aws") -// p.ApplyFn = testApplyFn -// p.DiffFn = testDiffFn +func TestContext2Apply_moduleOrphanProvider(t *testing.T) { + m := testModule(t, "apply-module-orphan-provider-inherit") + p := testProvider("aws") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn -// p.ConfigureFn = func(c *ResourceConfig) error { -// if _, ok := c.Get("value"); !ok { -// return fmt.Errorf("value is not found") -// } + p.ConfigureFn = func(c *ResourceConfig) error { + if _, ok := c.Get("value"); !ok { + return fmt.Errorf("value is not found") + } -// return nil -// } + return nil + } -// // Create a state with an orphan module -// state := &State{ -// Modules: []*ModuleState{ -// &ModuleState{ -// Path: []string{"root", "child"}, -// Resources: map[string]*ResourceState{ -// "aws_instance.bar": &ResourceState{ -// Type: "aws_instance", -// Primary: &InstanceState{ -// ID: "bar", -// }, -// }, -// }, -// }, -// }, -// } + // Create a state with an orphan module + state := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: []string{"root", "child"}, + Resources: map[string]*ResourceState{ + "aws_instance.bar": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + }, + }, + }, + }, + }, + } -// ctx := testContext2(t, &ContextOpts{ -// Module: m, -// State: state, -// ProviderResolver: ResourceProviderResolverFixed( -// map[string]ResourceProviderFactory{ -// "aws": testProviderFuncFixed(p), -// }, -// ), -// }) + ctx := testContext2(t, &ContextOpts{ + Module: m, + State: state, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), + }) -// if _, err := ctx.Plan(); err != nil { -// t.Fatalf("err: %s", err) -// } + if _, err := ctx.Plan(); err != nil { + t.Fatalf("err: %s", err) + } -// if _, err := ctx.Apply(); err != nil { -// t.Fatalf("err: %s", err) -// } -//} + if _, err := ctx.Apply(); err != nil { + t.Fatalf("err: %s", err) + } +} -//// FIXME: how do we handle this one? -//func TestContext2Apply_moduleOrphanGrandchildProvider(t *testing.T) { -// m := testModule(t, "apply-module-orphan-provider-inherit") -// p := testProvider("aws") -// p.ApplyFn = testApplyFn -// p.DiffFn = testDiffFn +func TestContext2Apply_moduleOrphanGrandchildProvider(t *testing.T) { + m := testModule(t, "apply-module-orphan-provider-inherit") + p := testProvider("aws") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn -// p.ConfigureFn = func(c *ResourceConfig) error { -// if _, ok := c.Get("value"); !ok { -// return fmt.Errorf("value is not found") -// } + p.ConfigureFn = func(c *ResourceConfig) error { + if _, ok := c.Get("value"); !ok { + return fmt.Errorf("value is not found") + } -// return nil -// } + return nil + } -// // Create a state with an orphan module that is nested (grandchild) -// state := &State{ -// Modules: []*ModuleState{ -// &ModuleState{ -// Path: []string{"root", "parent", "child"}, -// Resources: map[string]*ResourceState{ -// "aws_instance.bar": &ResourceState{ -// Type: "aws_instance", -// Primary: &InstanceState{ -// ID: "bar", -// }, -// }, -// }, -// }, -// }, -// } + // Create a state with an orphan module that is nested (grandchild) + state := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: []string{"root", "parent", "child"}, + Resources: map[string]*ResourceState{ + "aws_instance.bar": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + }, + }, + }, + }, + }, + } -// ctx := testContext2(t, &ContextOpts{ -// Module: m, -// State: state, -// ProviderResolver: ResourceProviderResolverFixed( -// map[string]ResourceProviderFactory{ -// "aws": testProviderFuncFixed(p), -// }, -// ), -// }) + ctx := testContext2(t, &ContextOpts{ + Module: m, + State: state, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), + }) -// if _, err := ctx.Plan(); err != nil { -// t.Fatalf("err: %s", err) -// } + if _, err := ctx.Plan(); err != nil { + t.Fatalf("err: %s", err) + } -// if _, err := ctx.Apply(); err != nil { -// t.Fatalf("err: %s", err) -// } -//} + if _, err := ctx.Apply(); err != nil { + t.Fatalf("err: %s", err) + } +} func TestContext2Apply_moduleGrandchildProvider(t *testing.T) { m := testModule(t, "apply-module-grandchild-provider-inherit") diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index f2fb0895d..8cf847e6d 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -321,55 +321,53 @@ func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) { } } -//// FIXME: provider must still exist in config, but we should be able to locate -//// it elsewhere -//func TestContext2Validate_moduleProviderInheritOrphan(t *testing.T) { -// m := testModule(t, "validate-module-pc-inherit-orphan") -// p := testProvider("aws") -// c := testContext2(t, &ContextOpts{ -// Module: m, -// ProviderResolver: ResourceProviderResolverFixed( -// map[string]ResourceProviderFactory{ -// "aws": testProviderFuncFixed(p), -// }, -// ), -// State: &State{ -// Modules: []*ModuleState{ -// &ModuleState{ -// Path: []string{"root", "child"}, -// Resources: map[string]*ResourceState{ -// "aws_instance.bar": &ResourceState{ -// Type: "aws_instance", -// Primary: &InstanceState{ -// ID: "bar", -// }, -// }, -// }, -// }, -// }, -// }, -// }) +func TestContext2Validate_moduleProviderInheritOrphan(t *testing.T) { + m := testModule(t, "validate-module-pc-inherit-orphan") + p := testProvider("aws") + c := testContext2(t, &ContextOpts{ + Module: m, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), + State: &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: []string{"root", "child"}, + Resources: map[string]*ResourceState{ + "aws_instance.bar": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + }, + }, + }, + }, + }, + }, + }) -// p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { -// v, ok := c.Get("set") -// if !ok { -// return nil, []error{fmt.Errorf("not set")} -// } -// if v != "bar" { -// return nil, []error{fmt.Errorf("bad: %#v", v)} -// } + p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { + v, ok := c.Get("set") + if !ok { + return nil, []error{fmt.Errorf("not set")} + } + if v != "bar" { + return nil, []error{fmt.Errorf("bad: %#v", v)} + } -// return nil, nil -// } + return nil, nil + } -// w, e := c.Validate() -// if len(w) > 0 { -// t.Fatalf("bad: %#v", w) -// } -// if len(e) > 0 { -// t.Fatalf("bad: %s", e) -// } -//} + w, e := c.Validate() + if len(w) > 0 { + t.Fatalf("bad: %#v", w) + } + if len(e) > 0 { + t.Fatalf("bad: %s", e) + } +} func TestContext2Validate_moduleProviderVar(t *testing.T) { m := testModule(t, "validate-module-pc-vars")