forked from coop-cloud-mirrors/godotenv
Extract a test helper
This commit is contained in:
parent
973cf53008
commit
d8dfdb69b3
@ -5,6 +5,21 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func loadEnvAndCompareValues(t *testing.T, envFileName string, expectedValues map[string]string) {
|
||||
err := Load(envFileName)
|
||||
if err != nil {
|
||||
t.Fatalf("Error loading %v", envFileName)
|
||||
}
|
||||
|
||||
for k := range expectedValues {
|
||||
envValue := os.Getenv(k)
|
||||
v := expectedValues[k]
|
||||
if envValue != v {
|
||||
t.Errorf("Mismatch for key '%v': expected '%v' got '%v'", k, v, envValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadFileNotFound(t *testing.T) {
|
||||
err := Load("somefilethatwillneverexistever.env")
|
||||
if err == nil {
|
||||
@ -14,11 +29,6 @@ func TestLoadFileNotFound(t *testing.T) {
|
||||
|
||||
func TestLoadPlainEnv(t *testing.T) {
|
||||
envFileName := "fixtures/plain.env"
|
||||
err := Load(envFileName)
|
||||
if err != nil {
|
||||
t.Fatalf("Error loading %v", envFileName)
|
||||
}
|
||||
|
||||
plainValues := map[string]string{
|
||||
"OPTION_A": "1",
|
||||
"OPTION_B": "2",
|
||||
@ -27,11 +37,5 @@ func TestLoadPlainEnv(t *testing.T) {
|
||||
"OPTION_E": "5",
|
||||
}
|
||||
|
||||
for k := range plainValues {
|
||||
envValue := os.Getenv(k)
|
||||
v := plainValues[k]
|
||||
if envValue != v {
|
||||
t.Errorf("Mismatch for key '%v': expected '%v' got '%v'", k, v, envValue)
|
||||
}
|
||||
}
|
||||
loadEnvAndCompareValues(t, envFileName, plainValues)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user