You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
778 B
Go
41 lines
778 B
Go
package common
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func assertString(t *testing.T, got, want string) {
|
|
t.Helper()
|
|
if got != want {
|
|
log.Fatalf("Assertion failed. Got: %s want: %s", got, want)
|
|
}
|
|
}
|
|
|
|
func TestGetDefaultEnv(t *testing.T) {
|
|
|
|
t.Run("test key exists", func(t *testing.T) {
|
|
//Setup
|
|
want := "test value"
|
|
os.Setenv("TEST_KEY", want)
|
|
got := GetDefaultEnv("TEST_KEY", "")
|
|
assertString(t, got, want)
|
|
os.Unsetenv("TEST_KEY")
|
|
})
|
|
|
|
t.Run("key does not exists", func(t *testing.T) {
|
|
//Setup
|
|
want := "another test value"
|
|
got := GetDefaultEnv("TEST_KEY", want)
|
|
assertString(t, got, want)
|
|
})
|
|
|
|
t.Run("key maps to empty value", func(t *testing.T) {
|
|
//Setup
|
|
want := ""
|
|
got := GetDefaultEnv("TEST_EMPTY_KEY", want)
|
|
assertString(t, got, want)
|
|
})
|
|
}
|