mirror of https://github.com/joho/godotenv.git
Make Load() without args open .env by default
parent
ac58adf673
commit
9d9f6ccb57
|
@ -9,6 +9,10 @@ import (
|
|||
)
|
||||
|
||||
func Load(filenames ...string) (err error) {
|
||||
if len(filenames) == 0 {
|
||||
filenames = []string{".env"}
|
||||
}
|
||||
|
||||
for _, filename := range filenames {
|
||||
err = loadFile(filename)
|
||||
if err != nil {
|
||||
|
|
|
@ -30,6 +30,13 @@ func loadEnvAndCompareValues(t *testing.T, envFileName string, expectedValues ma
|
|||
}
|
||||
}
|
||||
|
||||
func TestLoadWithNoArgsLoadsDotEnv(t *testing.T) {
|
||||
err := Load()
|
||||
if err.Error() != "open .env: no such file or directory" {
|
||||
t.Errorf("Didn't try and open .env by default")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadFileNotFound(t *testing.T) {
|
||||
err := Load("somefilethatwillneverexistever.env")
|
||||
if err == nil {
|
||||
|
|
Loading…
Reference in New Issue