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

use test environments for codegen tests #15884

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 22 additions & 15 deletions pkg/codegen/testing/test/sdk_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/pulumi/pulumi/pkg/v3/codegen"
ptesting "github.com/pulumi/pulumi/sdk/v3/go/common/testing"
)

// Defines an extra check logic that accepts the directory with the
Expand Down Expand Up @@ -559,11 +560,21 @@ func TestSDKCodegen(t *testing.T, opts *SDKCodegenOptions) { // revive:disable-l

t.Log(tt.Description)

e := ptesting.NewEnvironment(t)
defer e.DeleteIfNotFailed()

// Some tests need the directory to have the right name. Create a subdirectory
// under the test environment to ensure that
err := os.Mkdir(filepath.Join(e.RootPath, filepath.FromSlash(tt.Directory)), 0o755)
require.NoError(t, err)
e.CWD = filepath.Join(e.RootPath, filepath.FromSlash(tt.Directory))

dirPath := filepath.Join(testDir, filepath.FromSlash(tt.Directory))
e.ImportDirectory(dirPath)

schemaPath := filepath.Join(dirPath, "schema.json")
schemaPath := filepath.Join(e.CWD, "schema.json")
if _, err := os.Stat(schemaPath); err != nil && os.IsNotExist(err) {
schemaPath = filepath.Join(dirPath, "schema.yaml")
schemaPath = filepath.Join(e.CWD, "schema.yaml")
}

if tt.ShouldSkipCodegen(opts.Language) {
Expand All @@ -574,8 +585,8 @@ func TestSDKCodegen(t *testing.T, opts *SDKCodegenOptions) { // revive:disable-l
files, err := GeneratePackageFilesFromSchema(schemaPath, opts.GenPackage)
require.NoError(t, err)

if !RewriteFilesWhenPulumiAccept(t, dirPath, opts.Language, files) {
expectedFiles, err := LoadBaseline(dirPath, opts.Language)
if !RewriteFilesWhenPulumiAccept(t, e.CWD, opts.Language, files) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this break the PULUMI_ACCEPT flow? Because we're going to rewrite the files in the temp dir?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it does. We probably need to re-export these files.

The latest commit fixes that.

expectedFiles, err := LoadBaseline(e.CWD, opts.Language)
require.NoError(t, err)

if !ValidateFileEquality(t, files, expectedFiles) {
Expand All @@ -587,7 +598,7 @@ func TestSDKCodegen(t *testing.T, opts *SDKCodegenOptions) { // revive:disable-l
return
}

CopyExtraFiles(t, dirPath, opts.Language)
CopyExtraFiles(t, e.CWD, opts.Language)

// Merge language-specific global and
// test-specific checks, with test-specific
Expand All @@ -607,19 +618,15 @@ func TestSDKCodegen(t *testing.T, opts *SDKCodegenOptions) { // revive:disable-l
}
sort.Strings(checkOrder)

codeDir := filepath.Join(dirPath, opts.Language)
codeDir := filepath.Join(e.CWD, opts.Language)

// Perform the checks.
//nolint:paralleltest // test functions are ordered
for _, check := range checkOrder {
check := check
t.Run(check, func(t *testing.T) {
if tt.ShouldSkipTest(opts.Language, check) {
t.Skip()
}
checkFun := allChecks[check]
checkFun(t, codeDir)
})
if tt.ShouldSkipTest(opts.Language, check) {
t.Skip()
}
checkFun := allChecks[check]
checkFun(t, codeDir)
}
})
}
Expand Down