Skip to content

Commit

Permalink
Remove side effects from "eastest" package
Browse files Browse the repository at this point in the history
This removes the loading of the .env file which was the last side effect of
importing the "eastest" pkg.
  • Loading branch information
fabiante committed Dec 18, 2023
1 parent b45594c commit 010cc5a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
12 changes: 0 additions & 12 deletions eastest/clients.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package eastest

import (
"errors"
"fmt"
"os"
"sync"

"github.com/DEXPRO-Solutions-GmbH/easclient"
"github.com/joho/godotenv"
"gopkg.in/resty.v1"
)

Expand Down Expand Up @@ -39,13 +37,3 @@ func DefaultServerClient() *easclient.ServerClient {

return defaultServerClient
}

// init is run before any tests are executed.
// it loads the environment variables from .env and creates
// a default client for all tests to use.
func init() {
err := godotenv.Load(".env")
if errors.Is(err, os.ErrNotExist) {
return
}
}
22 changes: 22 additions & 0 deletions internal/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package internal

import (
"errors"
"os"
"testing"

"github.com/joho/godotenv"
)

// TestPrelude is used by tests of this library to ensure that they behave as expected in the context
// of our environments.
func TestPrelude(t *testing.T) {
// Having this function be called ensures that the init() function is called.
}

func init() {
err := godotenv.Load(".env")
if errors.Is(err, os.ErrNotExist) {
return
}
}
2 changes: 2 additions & 0 deletions r_get_record_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (

"github.com/DEXPRO-Solutions-GmbH/easclient"
"github.com/DEXPRO-Solutions-GmbH/easclient/eastest"
"github.com/DEXPRO-Solutions-GmbH/easclient/internal"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)

func TestStoreClient_GetRecordAttachment(t *testing.T) {
internal.TestPrelude(t)
eastest.SkipInCI(t)

ctx := context.Background()
Expand Down
2 changes: 2 additions & 0 deletions r_get_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (

"github.com/DEXPRO-Solutions-GmbH/easclient"
"github.com/DEXPRO-Solutions-GmbH/easclient/eastest"
"github.com/DEXPRO-Solutions-GmbH/easclient/internal"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)

func TestStoreClient_GetRecord(t *testing.T) {
internal.TestPrelude(t)
eastest.SkipInCI(t)

ctx := context.Background()
Expand Down
2 changes: 2 additions & 0 deletions r_get_store_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (

"github.com/DEXPRO-Solutions-GmbH/easclient"
"github.com/DEXPRO-Solutions-GmbH/easclient/eastest"
"github.com/DEXPRO-Solutions-GmbH/easclient/internal"
"github.com/stretchr/testify/require"
)

func TestStoreClient_GetStoreStatus(t *testing.T) {
internal.TestPrelude(t)
eastest.SkipInCI(t)

ctx := context.Background()
Expand Down
2 changes: 2 additions & 0 deletions r_put_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (

"github.com/DEXPRO-Solutions-GmbH/easclient"
"github.com/DEXPRO-Solutions-GmbH/easclient/eastest"
"github.com/DEXPRO-Solutions-GmbH/easclient/internal"
"github.com/stretchr/testify/require"
)

func TestStoreClient_PutStore(t *testing.T) {
internal.TestPrelude(t)
eastest.SkipInCI(t)

ctx := context.Background()
Expand Down

0 comments on commit 010cc5a

Please sign in to comment.