Skip to content

Commit

Permalink
Set up client once for acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-asawicki committed Dec 6, 2023
1 parent c189782 commit 7a685cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test: ## run unit and integration tests
go test -v -cover -timeout=30m ./...

test-acceptance: ## run acceptance tests
TF_ACC=1 go test -run "^TestAcc_" -v -cover -timeout=30m ./...
TF_ACC=1 SF_TF_ACC_TEST_CONFIGURE_CLIENT_ONCE=true go test -run "^TestAcc_" -v -cover -timeout=30m ./...

test-architecture: ## check architecture constraints between packages
go test ./pkg/architests/... -v
Expand Down
21 changes: 17 additions & 4 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"net"
"net/url"
"os"
"sync"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -737,9 +739,20 @@ func ConfigureProvider(s *schema.ResourceData) (interface{}, error) {
config = sdk.MergeConfig(config, profileConfig)
}
}
client, err := sdk.NewClient(config)
if err != nil {
return nil, err

if os.Getenv("TF_ACC") != "" && os.Getenv("SF_TF_ACC_TEST_CONFIGURE_CLIENT_ONCE") == "true" {
once.Do(func() {
configuredClient, configureClientErr = sdk.NewClient(config)
})
} else {
configuredClient, configureClientErr = sdk.NewClient(config)
}
return client.GetConn().DB, nil
if configureClientErr != nil {
return nil, configureClientErr
}
return configuredClient.GetConn().DB, nil
}

var once sync.Once

Check failure on line 756 in pkg/provider/provider.go

View workflow job for this annotation

GitHub Actions / reviewdog

[golangci] reported by reviewdog 🐶 File is not `gofumpt`-ed (gofumpt) Raw Output: pkg/provider/provider.go:756: File is not `gofumpt`-ed (gofumpt) var once sync.Once var configuredClient *sdk.Client var configureClientErr error
var configuredClient *sdk.Client
var configureClientErr error

Check failure on line 758 in pkg/provider/provider.go

View workflow job for this annotation

GitHub Actions / reviewdog

the variable name `configureClientErr` should conform to the `errXxx` format (errname)

Check failure on line 758 in pkg/provider/provider.go

View workflow job for this annotation

GitHub Actions / reviewdog

[golangci] reported by reviewdog 🐶 the variable name `configureClientErr` should conform to the `errXxx` format (errname) Raw Output: pkg/provider/provider.go:758:5: the variable name `configureClientErr` should conform to the `errXxx` format (errname) var configureClientErr error ^

0 comments on commit 7a685cf

Please sign in to comment.