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

Require local provider in tests #2953

Merged
merged 7 commits into from
Nov 16, 2023
Merged
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ install_plugins: .pulumi/bin/pulumi
lint_provider: provider
cd provider && golangci-lint run -c ../.golangci.yml

provider: tfgen install_plugins
provider_no_deps:
VenelinMartinov marked this conversation as resolved.
Show resolved Hide resolved
(cd provider && go build $(PULUMI_PROVIDER_BUILD_PARALLELISM) -o $(WORKING_DIR)/bin/$(PROVIDER) -ldflags "-X $(PROJECT)/$(VERSION_PATH)=$(VERSION) -X github.com/hashicorp/terraform-provider-aws/version.ProviderVersion=$(VERSION)" $(PROJECT)/$(PROVIDER_PATH)/cmd/$(PROVIDER))

provider: tfgen install_plugins provider_no_deps

test:
cd examples && go test -v -tags=all -parallel $(TESTPARALLELISM) -timeout 2h

Expand Down
37 changes: 37 additions & 0 deletions examples/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package examples

import (
"log"
"os"
"os/exec"
"path/filepath"
"testing"
)

func TestMain(m *testing.M) {
disableProviderBuild := os.Getenv("GITHUB_ACTIONS")
if disableProviderBuild == "" {
cwd, err := os.Getwd()
if err != nil {
log.Println("Unable to get working directory!")
os.Exit(1)
}
command := exec.Command("make", "provider_no_deps")
command.Dir = filepath.Join(cwd, "..")
err = command.Run()
if err != nil {
log.Println("Unable to build provider!")
os.Exit(1)
}

binPath := filepath.Join(cwd, "..", "bin")
err = os.Setenv("PATH", binPath+":"+os.Getenv("PATH"))
VenelinMartinov marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Println("Unable to set PATH!")
os.Exit(1)
}
}

exitVal := m.Run()
os.Exit(exitVal)
}
Loading