terraform: simplify the shadow component factory

This unifies shadow/real under one since it was really just a basic
switch of what to return.
This commit is contained in:
Mitchell Hashimoto 2016-10-03 19:39:27 -07:00
parent 89e8656c6b
commit 8ef35d7561
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 17 additions and 22 deletions

View File

@ -16,13 +16,14 @@ func newShadowComponentFactory(
shared := &shadowComponentFactoryShared{contextComponentFactory: f}
// Create the real side
real := &shadowComponentFactoryReal{
real := &shadowComponentFactory{
shadowComponentFactoryShared: shared,
}
// Create the shadow
shadow := &shadowComponentFactory{
shadowComponentFactoryShared: shared,
Shadow: true,
}
return real, shadow
@ -32,36 +33,30 @@ func newShadowComponentFactory(
// with this factory are fake and will not cause real work to happen.
type shadowComponentFactory struct {
*shadowComponentFactoryShared
Shadow bool // True if this should return the shadow
}
func (f *shadowComponentFactory) ResourceProvider(
n, uid string) (ResourceProvider, error) {
_, shadow, err := f.shadowComponentFactoryShared.ResourceProvider(n, uid)
return shadow, err
real, shadow, err := f.shadowComponentFactoryShared.ResourceProvider(n, uid)
var result ResourceProvider = real
if f.Shadow {
result = shadow
}
return result, err
}
func (f *shadowComponentFactory) ResourceProvisioner(
n, uid string) (ResourceProvisioner, error) {
_, shadow, err := f.shadowComponentFactoryShared.ResourceProvisioner(n, uid)
return shadow, err
real, shadow, err := f.shadowComponentFactoryShared.ResourceProvisioner(n, uid)
var result ResourceProvisioner = real
if f.Shadow {
result = shadow
}
// shadowComponentFactoryReal is the real side of the component factory.
// Operations here result in real components that do real work.
type shadowComponentFactoryReal struct {
*shadowComponentFactoryShared
}
func (f *shadowComponentFactoryReal) ResourceProvider(
n, uid string) (ResourceProvider, error) {
real, _, err := f.shadowComponentFactoryShared.ResourceProvider(n, uid)
return real, err
}
func (f *shadowComponentFactoryReal) ResourceProvisioner(
n, uid string) (ResourceProvisioner, error) {
real, _, err := f.shadowComponentFactoryShared.ResourceProvisioner(n, uid)
return real, err
return result, err
}
// shadowComponentFactoryShared is shared data between the two factories.