Skip to content

Commit

Permalink
load env file in runner_testing (#54)
Browse files Browse the repository at this point in the history
When we use Gonkey as a library, we may also want to use env-file.

Also here is little cleanup of env-file loading in main.go
JustSkiv authored Aug 14, 2020
1 parent dbf85c2 commit 02fd94f
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -79,9 +79,10 @@ func main() {
log.Fatal(errors.New("you should specify db_dsn to load fixtures"))
}

err := godotenv.Load(config.EnvFile)
if err != nil && config.EnvFile != "" {
log.Println(errors.New("error loading .env file"), err)
if config.EnvFile != "" {
if err := godotenv.Load(config.EnvFile); err != nil {
log.Println(errors.New("can't load .env file"), err)
}
}

r := runner.New(
9 changes: 9 additions & 0 deletions runner/runner_testing.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@ import (
"os"
"testing"

"github.com/joho/godotenv"

"github.com/lamoda/gonkey/checker/response_body"
"github.com/lamoda/gonkey/checker/response_db"
"github.com/lamoda/gonkey/checker/response_header"
@@ -23,6 +25,7 @@ type RunWithTestingParams struct {
Mocks *mocks.Mocks
FixturesDir string
DB *sql.DB
EnvFilePath string
}

// RunWithTesting is a helper function the wraps the common Run and provides simple way
@@ -33,6 +36,12 @@ func RunWithTesting(t *testing.T, params *RunWithTestingParams) {
mocksLoader = mocks.NewLoader(params.Mocks)
}

if params.EnvFilePath != "" {
if err := godotenv.Load(params.EnvFilePath); err != nil {
t.Fatal(err)
}
}

debug := os.Getenv("GONKEY_DEBUG") != ""

var fixturesLoader *fixtures.Loader

0 comments on commit 02fd94f

Please sign in to comment.