Skip to content

Commit

Permalink
Merge #13253
Browse files Browse the repository at this point in the history
13253: Fix failing test TestCreatingStackWithNumericName r=dixler a=dixler

`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.

Co-authored-by: Kyle Dixler <kyle@pulumi.com>
  • Loading branch information
bors[bot] and Kyle Dixler committed Jun 22, 2023
2 parents 2f424ee + 0a62734 commit 5203472
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/cmd/pulumi/new_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
"context"
"os"
"path/filepath"
"strconv"
"strings"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 5203472

Please sign in to comment.