Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests failing on Windows #4

Merged
merged 3 commits into from
Jul 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions godotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ and all the env vars declared in .env will be avaiable through os.Getenv("SOME_E
package godotenv

import (
"bufio"
"errors"
"io/ioutil"
"os"
"strings"
)
Expand Down Expand Up @@ -87,14 +87,21 @@ func loadFile(filename string) (err error) {
}

func readFile(filename string) (envMap map[string]string, err error) {
content, err := ioutil.ReadFile(filename)
file, err := os.Open(filename)

// content, err := ioutil.ReadFile(filename)
if err != nil {
return
}
defer file.Close()

envMap = make(map[string]string)

lines := strings.Split(string(content), "\n")
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}

for _, fullLine := range lines {
if !isIgnoredLine(fullLine) {
Expand Down
3 changes: 2 additions & 1 deletion godotenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ 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" {
pathError := err.(*os.PathError)
if pathError == nil || pathError.Op != "open" || pathError.Path != ".env"{
t.Errorf("Didn't try and open .env by default")
}
}
Expand Down