Skip to content

Commit

Permalink
build provider and add to path as part of tests, add an env var for C…
Browse files Browse the repository at this point in the history
…I to avoid this
  • Loading branch information
VenelinMartinov committed Nov 13, 2023
1 parent 8d81571 commit eea13c4
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions examples/main_test.go
Expand Up @@ -9,23 +9,27 @@ import (
)

func TestMain(m *testing.M) {
// Ensure we use a locally built provider
awsProviderPath, err := exec.LookPath("pulumi-resource-aws")
if err != nil {
log.Println("AWS provider not found in path!")
os.Exit(1)
}

cwd, err := os.Getwd()
if err != nil {
log.Println("Unable to get working directory!")
os.Exit(1)
}
desiredPath := filepath.Join(cwd, "..", "bin", "pulumi-resource-aws")
disableProviderBuild := os.Getenv("DISABLE_PROVIDER_BUILD")
if disableProviderBuild == "" {
cwd, err := os.Getwd()
if err != nil {
log.Println("Unable to get working directory!")
os.Exit(1)
}
command := exec.Command("make", "provider", "-o", "tfgen", "-o", "install_plugins")
command.Dir = filepath.Join(cwd, "..")
err = command.Run()
if err != nil {
log.Println("Unable to build provider!")
os.Exit(1)
}

if awsProviderPath != desiredPath {
log.Println("AWS provider not built locally!")
os.Exit(1)
binPath := filepath.Join(cwd, "..", "bin")
err = os.Setenv("PATH", binPath+":"+os.Getenv("PATH"))
if err != nil {
log.Println("Unable to set PATH!")
os.Exit(1)
}
}

exitVal := m.Run()
Expand Down

0 comments on commit eea13c4

Please sign in to comment.