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:
parent
89e8656c6b
commit
8ef35d7561
|
@ -16,13 +16,14 @@ func newShadowComponentFactory(
|
||||||
shared := &shadowComponentFactoryShared{contextComponentFactory: f}
|
shared := &shadowComponentFactoryShared{contextComponentFactory: f}
|
||||||
|
|
||||||
// Create the real side
|
// Create the real side
|
||||||
real := &shadowComponentFactoryReal{
|
real := &shadowComponentFactory{
|
||||||
shadowComponentFactoryShared: shared,
|
shadowComponentFactoryShared: shared,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the shadow
|
// Create the shadow
|
||||||
shadow := &shadowComponentFactory{
|
shadow := &shadowComponentFactory{
|
||||||
shadowComponentFactoryShared: shared,
|
shadowComponentFactoryShared: shared,
|
||||||
|
Shadow: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
return real, shadow
|
return real, shadow
|
||||||
|
@ -32,36 +33,30 @@ func newShadowComponentFactory(
|
||||||
// with this factory are fake and will not cause real work to happen.
|
// with this factory are fake and will not cause real work to happen.
|
||||||
type shadowComponentFactory struct {
|
type shadowComponentFactory struct {
|
||||||
*shadowComponentFactoryShared
|
*shadowComponentFactoryShared
|
||||||
|
|
||||||
|
Shadow bool // True if this should return the shadow
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *shadowComponentFactory) ResourceProvider(
|
func (f *shadowComponentFactory) ResourceProvider(
|
||||||
n, uid string) (ResourceProvider, error) {
|
n, uid string) (ResourceProvider, error) {
|
||||||
_, shadow, err := f.shadowComponentFactoryShared.ResourceProvider(n, uid)
|
real, shadow, err := f.shadowComponentFactoryShared.ResourceProvider(n, uid)
|
||||||
return shadow, err
|
var result ResourceProvider = real
|
||||||
|
if f.Shadow {
|
||||||
|
result = shadow
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *shadowComponentFactory) ResourceProvisioner(
|
func (f *shadowComponentFactory) ResourceProvisioner(
|
||||||
n, uid string) (ResourceProvisioner, error) {
|
n, uid string) (ResourceProvisioner, error) {
|
||||||
_, shadow, err := f.shadowComponentFactoryShared.ResourceProvisioner(n, uid)
|
real, shadow, err := f.shadowComponentFactoryShared.ResourceProvisioner(n, uid)
|
||||||
return shadow, err
|
var result ResourceProvisioner = real
|
||||||
|
if f.Shadow {
|
||||||
|
result = shadow
|
||||||
}
|
}
|
||||||
|
|
||||||
// shadowComponentFactoryReal is the real side of the component factory.
|
return result, err
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// shadowComponentFactoryShared is shared data between the two factories.
|
// shadowComponentFactoryShared is shared data between the two factories.
|
||||||
|
|
Loading…
Reference in New Issue