mirror of https://github.com/pulumi/pulumi.git
Use a new PULUMI_HOME for every test environment (#15559)
<!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Should help with issues like https://github.com/pulumi/pulumi/issues/15240, and other cases of test case contamination. Run every new `testing.Environment` with a new PULUMI_HOME. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
This commit is contained in:
parent
9544fb00e3
commit
2840708bb2
|
@ -42,6 +42,8 @@ const (
|
|||
type Environment struct {
|
||||
*testing.T
|
||||
|
||||
// HomePath is the PULUMI_HOME directory for the environment
|
||||
HomePath string
|
||||
// RootPath is a new temp directory where the environment starts.
|
||||
RootPath string
|
||||
// Current working directory, defaults to the root path.
|
||||
|
@ -94,9 +96,14 @@ func NewEnvironment(t *testing.T) *Environment {
|
|||
assert.NoError(t, err, "creating temp directory")
|
||||
assert.NoError(t, WriteYarnRCForTest(root), "writing .yarnrc file")
|
||||
|
||||
// We always use a clean PULUMI_HOME for each environment to avoid any potential conflicts with plugins or config.
|
||||
home, err := os.MkdirTemp("", "test-env-home")
|
||||
assert.NoError(t, err, "creating temp PULUMI_HOME directory")
|
||||
|
||||
t.Logf("Created new test environment: %v", root)
|
||||
return &Environment{
|
||||
T: t,
|
||||
HomePath: home,
|
||||
RootPath: root,
|
||||
CWD: root,
|
||||
}
|
||||
|
@ -242,6 +249,7 @@ func (e *Environment) GetCommandResultsIn(dir string, command string, args ...st
|
|||
cmd.Env = os.Environ()
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", pulumiCredentialsPathEnvVar, e.RootPath))
|
||||
cmd.Env = append(cmd.Env, "PULUMI_DEBUG_COMMANDS=true")
|
||||
cmd.Env = append(cmd.Env, "PULUMI_HOME="+e.HomePath)
|
||||
if !e.NoPassphrase {
|
||||
cmd.Env = append(cmd.Env, "PULUMI_CONFIG_PASSPHRASE="+passphrase)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
|
||||
|
||||
ptesting "github.com/pulumi/pulumi/sdk/v3/go/common/testing"
|
||||
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -253,10 +252,8 @@ func TestPackageGetSchema(t *testing.T) {
|
|||
bindSchema(schemaJSON)
|
||||
|
||||
// Now try to get the schema from the path to the binary
|
||||
pulumiHome, err := workspace.GetPulumiHomeDir()
|
||||
require.NoError(t, err)
|
||||
binaryPath := filepath.Join(
|
||||
pulumiHome,
|
||||
e.HomePath,
|
||||
"plugins",
|
||||
"resource-random-v4.13.0",
|
||||
"pulumi-resource-random")
|
||||
|
|
Loading…
Reference in New Issue