This commit is contained in:
Mitchell Hashimoto 2016-09-26 18:01:02 -07:00
parent 1df3bbdc37
commit f73dc844c7
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 41 additions and 7 deletions

View File

@ -239,6 +239,19 @@ func TestResourceConfigGet(t *testing.T) {
}
}
func TestResourceConfigEqual_nil(t *testing.T) {
var nilRc *ResourceConfig
notNil := NewResourceConfig(nil)
if nilRc.Equal(notNil) {
t.Fatal("should not be equal")
}
if notNil.Equal(nilRc) {
t.Fatal("should not be equal")
}
}
func testResourceConfig(
t *testing.T, c map[string]interface{}) *ResourceConfig {
raw, err := config.NewRawConfig(c)

View File

@ -84,6 +84,18 @@ func (p *shadowResourceProviderReal) Close() error {
return result
}
func (p *shadowResourceProviderReal) Input(
input UIInput, c *ResourceConfig) (*ResourceConfig, error) {
result, err := p.ResourceProvider.Input(input, c)
p.Shared.Input.SetValue(&shadowResourceProviderInput{
Config: c,
Result: result,
ResultErr: err,
})
return result, err
}
// shadowResourceProviderShadow is the shadow resource provider. Function
// calls never affect real resources. This is paired with the "real" side
// which must be called properly to enable recording.
@ -130,12 +142,6 @@ func (p *shadowResourceProviderShadow) Close() error {
return v.(error)
}
type shadowResourceProviderInput struct {
Config *ResourceConfig
Result *ResourceConfig
ResultErr error
}
func (p *shadowResourceProviderShadow) Input(
input UIInput, c *ResourceConfig) (*ResourceConfig, error) {
// Get the result of the input call
@ -154,7 +160,13 @@ func (p *shadowResourceProviderShadow) Input(
}
// Compare the parameters, which should be identical
// TODO
if !c.Equal(result.Config) {
p.ErrorLock.Lock()
p.Error = multierror.Append(p.Error, fmt.Errorf(
"Input had unequal configurations (real, then shadow):\n\n%#v\n\n%#v",
result.Config, c))
p.ErrorLock.Unlock()
}
// Return the results
return result.Result, result.ResultErr
@ -217,3 +229,12 @@ func (p *shadowResourceProviderShadow) ReadDataApply(
d *InstanceDiff) (*InstanceState, error) {
return nil, nil
}
// The structs for the various function calls are put below. These structs
// are used to carry call information across the real/shadow boundaries.
type shadowResourceProviderInput struct {
Config *ResourceConfig
Result *ResourceConfig
ResultErr error
}