helper/schema: tests for EnvDefaultFunc

/cc @jefferai - In case you care
This commit is contained in:
Mitchell Hashimoto 2015-01-16 10:54:43 -08:00
parent b3e77ef244
commit 41029f8daa
1 changed files with 31 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package schema
import (
"os"
"reflect"
"testing"
@ -9,6 +10,36 @@ import (
"github.com/hashicorp/terraform/terraform"
)
func TestEnvDefaultFunc(t *testing.T) {
key := "TF_TEST_ENV_DEFAULT_FUNC"
defer os.Unsetenv(key)
f := EnvDefaultFunc(key, "42")
if err := os.Setenv(key, "foo"); err != nil {
t.Fatalf("err: %s", err)
}
actual, err := f()
if err != nil {
t.Fatalf("err: %s", err)
}
if actual != "foo" {
t.Fatalf("bad: %#v", actual)
}
if err := os.Unsetenv(key); err != nil {
t.Fatalf("err: %s", err)
}
actual, err = f()
if err != nil {
t.Fatalf("err: %s", err)
}
if actual != "42" {
t.Fatalf("bad: %#v", actual)
}
}
func TestValueType_Zero(t *testing.T) {
cases := []struct {
Type ValueType