terraform: add ResourceProviderFactoryFixed

This commit is contained in:
Mitchell Hashimoto 2014-07-10 09:46:21 -07:00
parent 74f6e3fd9c
commit 3a79a1ca1a
2 changed files with 20 additions and 0 deletions

View File

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

View File

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