diff --git a/terraform/shadow_eval_context.go b/terraform/shadow_eval_context.go index 48b8812fe..d1fc90272 100644 --- a/terraform/shadow_eval_context.go +++ b/terraform/shadow_eval_context.go @@ -32,7 +32,7 @@ type ShadowEvalContext interface { // itself. In this scenario, you should not compare diffs/states since // they can't be considered accurate since operations during execution // failed. - Close() error + CloseShadow() error } // NewShadowEvalContext creates a new shadowed EvalContext. This returns @@ -156,6 +156,11 @@ type shadowEvalContextShared struct { Providers shadow.KeyedValue } +func (c *shadowEvalContextShadow) CloseShadow() error { + // TODO: somehow shut this thing down + return c.Error +} + func (c *shadowEvalContextShadow) Path() []string { return c.PathValue } @@ -211,7 +216,6 @@ func (c *shadowEvalContextShadow) err(err error) error { // TODO: All the functions below are EvalContext functions that must be impl. -func (c *shadowEvalContextShadow) Close() error { return nil } func (c *shadowEvalContextShadow) Input() UIInput { return nil } func (c *shadowEvalContextShadow) Provider(n string) ResourceProvider { return nil } func (c *shadowEvalContextShadow) CloseProvider(n string) error { return nil } diff --git a/terraform/shadow_eval_context_test.go b/terraform/shadow_eval_context_test.go index 2123e4816..cbcd1db17 100644 --- a/terraform/shadow_eval_context_test.go +++ b/terraform/shadow_eval_context_test.go @@ -71,4 +71,38 @@ func TestShadowEvalContextInitProvider(t *testing.T) { if err := result.Configure(nil); !reflect.DeepEqual(err, mockErr) { t.Fatalf("bad: %#v", err) } + + // Verify we have no errors + if err := shadow.CloseShadow(); err != nil { + t.Fatalf("bad: %s", err) + } +} + +func TestShadowEvalContextInitProvider_doubleInit(t *testing.T) { + mock := new(MockEvalContext) + real, shadow := NewShadowEvalContext(mock) + + // Args, results + name := "foo" + mockResult := new(MockResourceProvider) + + // Configure the mock + mock.InitProviderProvider = mockResult + + // Call the real func + real.InitProvider(name) + + // Get the provider twice + shadow.InitProvider(name) + p, err := shadow.InitProvider(name) + if err != nil { + t.Fatalf("err: %s", err) + } + if p == nil { + t.Fatal("should return provider") + } + + if err := shadow.CloseShadow(); err == nil { + t.Fatal("should error") + } }