terraform: EvalContext.CloseProvider (shadow) works if never init
This commit is contained in:
parent
d6168edc50
commit
3504054b1e
|
@ -229,7 +229,12 @@ func (c *shadowEvalContextShadow) Provider(n string) ResourceProvider {
|
|||
|
||||
func (c *shadowEvalContextShadow) CloseProvider(n string) error {
|
||||
// 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 {
|
||||
c.err(fmt.Errorf(
|
||||
"Unknown 'CloseProvider' call for %q", n))
|
||||
|
|
|
@ -234,3 +234,24 @@ func TestShadowEvalContextCloseProvider_noInitClose(t *testing.T) {
|
|||
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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue