terraform/diff/lazy_resource_map_test.go

46 lines
836 B
Go
Raw Normal View History

2014-06-18 04:06:13 +02:00
package diff
import (
"testing"
)
func TestLazyResourceMap(t *testing.T) {
rb1 := new(ResourceBuilder)
rb2 := new(ResourceBuilder)
rm := &LazyResourceMap{
Resources: map[string]ResourceBuilderFactory{
"foo": testRBFactory(rb1),
"bar": testRBFactory(rb2),
"diff": func() *ResourceBuilder {
return new(ResourceBuilder)
},
},
}
actual := rm.Get("foo")
if actual == nil {
t.Fatal("should not be nil")
}
if actual != rb1 {
t.Fatalf("bad: %p %p", rb1, actual)
}
if actual == rm.Get("bar") {
t.Fatalf("bad: %p %p", actual, rm.Get("bar"))
}
actual = rm.Get("diff")
if actual == nil {
t.Fatal("should not be nil")
}
if actual != rm.Get("diff") {
t.Fatal("should memoize")
}
}
func testRBFactory(rb *ResourceBuilder) ResourceBuilderFactory {
return func() *ResourceBuilder {
return rb
}
}