package envtool import ( "os" "strconv" "testing" "github.com/fiskerinc/cloud-services/pkg/testhelper" ) var defaultValue = "DEFAULT_VALUE" var existingValue = "EXISTING_VALUE" var defaultInt = 0 var existingInt = 1 var defaultBool = false var existingBool = true func TestGetEnvDefaultValue(t *testing.T) { got := GetEnv("NON_EXISTING", defaultValue) if got != defaultValue { t.Errorf(testhelper.TestErrorTemplate, "Default value", defaultValue, got) } } func TestGetEnvExistingValue(t *testing.T) { const envName = "EXISTING" os.Setenv(envName, existingValue) got := GetEnv(envName, defaultValue) if got != existingValue { t.Errorf(testhelper.TestErrorTemplate, "Existing value", existingValue, got) } } func TestGetEnvIntDefaultValue(t *testing.T) { got := GetEnvInt("NON_EXISTING", defaultInt) if got != defaultInt { t.Errorf(testhelper.TestErrorTemplate, "Default value", defaultInt, got) } } func TestGetEnvIntExistingValue(t *testing.T) { const envName = "EXISTING" os.Setenv(envName, strconv.Itoa(existingInt)) got := GetEnvInt(envName, defaultInt) if got != existingInt { t.Errorf(testhelper.TestErrorTemplate, "Existing value", existingInt, got) } } func TestGetEnvBoolDefaultValue(t *testing.T) { got := GetEnvBool("NON_EXISTING", defaultBool) if got != defaultBool { t.Errorf(testhelper.TestErrorTemplate, "Default Value", defaultBool, got) } } func TestGetEnvBoolExistingValue(t *testing.T) { const envName = "EXISTING" os.Setenv(envName, strconv.FormatBool(existingBool)) got := GetEnvBool(envName, defaultBool) if got != existingBool { t.Errorf(testhelper.TestErrorTemplate, "Default Value", existingBool, got) } }