24 lines
589 B
Go
24 lines
589 B
Go
package utility
|
|
|
|
import "testing"
|
|
|
|
func TestLazy_Value(t *testing.T) {
|
|
i := 0
|
|
someLazyValue := NewLazy(func() (value interface{}, err error) {
|
|
value = "some lazy value"
|
|
i++
|
|
return
|
|
})
|
|
var theValueOfSomeLazyValue string
|
|
if err := someLazyValue.Value(&theValueOfSomeLazyValue); err != nil {
|
|
t.Fatalf("get value failed, %s", err)
|
|
}
|
|
t.Logf("value of lazy: %s", theValueOfSomeLazyValue)
|
|
if err := someLazyValue.Value(&theValueOfSomeLazyValue); err != nil {
|
|
t.Fatalf("get value failed, %s", err)
|
|
}
|
|
if i > 1 {
|
|
t.Fatalf("lazy should only evaluate once, but %d times", i)
|
|
}
|
|
}
|