From 0a62734817f78697848319f75f230ca6f11a349f Mon Sep 17 00:00:00 2001 From: Kyle Dixler Date: Thu, 22 Jun 2023 14:22:33 -0700 Subject: [PATCH] Fix failing test `TestCreatingStackWithNumericName` is failing due to using a constant project name. A failed test run may leave a project behind so we now use a unix timestamp to try to guarantee uniqueness. --- pkg/cmd/pulumi/new_acceptance_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/pulumi/new_acceptance_test.go b/pkg/cmd/pulumi/new_acceptance_test.go index c12f0ce724d4..78ebc287949d 100644 --- a/pkg/cmd/pulumi/new_acceptance_test.go +++ b/pkg/cmd/pulumi/new_acceptance_test.go @@ -17,8 +17,10 @@ import ( "context" "os" "path/filepath" + "strconv" "strings" "testing" + "time" "github.com/stretchr/testify/require" @@ -66,13 +68,22 @@ func TestCreatingStackWithArgsSpecifiedName(t *testing.T) { //nolint:paralleltest // changes directory for process func TestCreatingStackWithNumericName(t *testing.T) { + skipIfShortOrNoPulumiAccessToken(t) + tempdir := t.TempDir() chdir(t, tempdir) + // This test requires a numeric project name. + // Project names have to be unique or this test will fail. + // A test may crash and leave a project behind, so we use a timestamp to try to ensure uniqueness + // instead of a constant. + unixTsNanos := time.Now().UnixNano() + numericProjectName := strconv.Itoa(int(unixTsNanos)) + args := newArgs{ interactive: false, yes: true, - name: "123456", // Should be serialized as a string. + name: numericProjectName, // Should be serialized as a string. prompt: promptForValue, secretsProvider: "default", stack: stackName, @@ -85,7 +96,7 @@ func TestCreatingStackWithNumericName(t *testing.T) { p := loadProject(t, tempdir) assert.NotNil(t, p) - assert.Equal(t, p.Name.String(), "123456") + assert.Equal(t, p.Name.String(), numericProjectName) assert.Equal(t, stackName, loadStackName(t)) removeStack(t, tempdir, stackName)