terraform: add ResourceProviderFactoryFixed
This commit is contained in:
parent
74f6e3fd9c
commit
3a79a1ca1a
|
@ -69,6 +69,14 @@ type ResourceType struct {
|
|||
// of a resource provider.
|
||||
type ResourceProviderFactory func() (ResourceProvider, error)
|
||||
|
||||
// ResourceProviderFactoryFixed is a helper that creates a
|
||||
// ResourceProviderFactory that just returns some fixed provider.
|
||||
func ResourceProviderFactoryFixed(p ResourceProvider) ResourceProviderFactory {
|
||||
return func() (ResourceProvider, error) {
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
|
||||
func ProviderSatisfies(p ResourceProvider, n string) bool {
|
||||
for _, rt := range p.Resources() {
|
||||
if rt.Name == n {
|
||||
|
|
|
@ -175,3 +175,15 @@ func TestResourceConfig_IsSet_nil(t *testing.T) {
|
|||
t.Fatal("bad")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceProviderFactoryFixed(t *testing.T) {
|
||||
p := new(MockResourceProvider)
|
||||
var f ResourceProviderFactory = ResourceProviderFactoryFixed(p)
|
||||
actual, err := f()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if actual != p {
|
||||
t.Fatal("should be identical")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue