forked from coop-cloud-mirrors/godotenv
42 lines
874 B
Go
42 lines
874 B
Go
package godotenv
|
|
|
|
import (
|
|
"os"
|
|
"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 {
|
|
t.Error("File wasn't found but Load didn't return an error")
|
|
}
|
|
}
|
|
|
|
func TestLoadPlainEnv(t *testing.T) {
|
|
envFileName := "fixtures/plain.env"
|
|
plainValues := map[string]string{
|
|
"OPTION_A": "1",
|
|
"OPTION_B": "2",
|
|
"OPTION_C": "3",
|
|
"OPTION_D": "4",
|
|
"OPTION_E": "5",
|
|
}
|
|
|
|
loadEnvAndCompareValues(t, envFileName, plainValues)
|
|
}
|