terraform: EvalContext.CloseProvider (shadow) works if never init

This commit is contained in:
Mitchell Hashimoto 2016-10-01 13:11:32 -07:00
parent d6168edc50
commit 3504054b1e
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 27 additions and 1 deletions

View File

@ -229,7 +229,12 @@ func (c *shadowEvalContextShadow) Provider(n string) ResourceProvider {
func (c *shadowEvalContextShadow) CloseProvider(n string) error { func (c *shadowEvalContextShadow) CloseProvider(n string) error {
// Wait for the provider value // Wait for the provider value
raw := c.Shared.Providers.Value(n) raw, ok := c.Shared.Providers.ValueOk(n)
if !ok {
c.err(fmt.Errorf(
"CloseProvider called for uninitialized provider %q", n))
return nil
}
if raw == nil { if raw == nil {
c.err(fmt.Errorf( c.err(fmt.Errorf(
"Unknown 'CloseProvider' call for %q", n)) "Unknown 'CloseProvider' call for %q", n))

View File

@ -234,3 +234,24 @@ func TestShadowEvalContextCloseProvider_noInitClose(t *testing.T) {
t.Fatal("should error") t.Fatal("should error")
} }
} }
func TestShadowEvalContextCloseProvider_noCreate(t *testing.T) {
mock := new(MockEvalContext)
_, shadow := NewShadowEvalContext(mock)
// Args, results
name := "foo"
mockResult := new(MockResourceProvider)
// Configure the mock
mock.InitProviderProvider = mockResult
// Close the provider
if err := shadow.CloseProvider(name); err != nil {
t.Fatalf("err: %s", err)
}
if err := shadow.CloseShadow(); err == nil {
t.Fatal("should error")
}
}