Production state
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadDotEnv(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), ".env")
|
||||
contents := "# comment\nDOTENV_TEST_ONE=value\nDOTENV_TEST_TWO=Preface Tools - Comic Animator\nDOTENV_TEST_THREE=\"quoted value\"\n"
|
||||
if err := os.WriteFile(path, []byte(contents), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("DOTENV_TEST_ONE", "existing")
|
||||
if err := LoadDotEnv(path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := os.Getenv("DOTENV_TEST_ONE"); got != "existing" {
|
||||
t.Fatalf("existing environment overwritten: %q", got)
|
||||
}
|
||||
if got := os.Getenv("DOTENV_TEST_TWO"); got != "Preface Tools - Comic Animator" {
|
||||
t.Fatalf("unquoted value: %q", got)
|
||||
}
|
||||
if got := os.Getenv("DOTENV_TEST_THREE"); got != "quoted value" {
|
||||
t.Fatalf("quoted value: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadDotEnvMissingFile(t *testing.T) {
|
||||
if err := LoadDotEnv(filepath.Join(t.TempDir(), "missing")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user