terraform: EvalContext.InitProvider(shadow) test double init

This commit is contained in:
Mitchell Hashimoto 2016-09-30 22:02:35 -07:00
parent 792a9f1de4
commit ce56712473
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 40 additions and 2 deletions

View File

@ -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 }

View File

@ -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")
}
}