2021-07-28 01:00:39 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
2022-07-20 22:12:02 +00:00
|
|
|
"bufio"
|
2021-07-28 01:00:39 +00:00
|
|
|
"bytes"
|
2022-10-10 23:01:53 +00:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2021-07-28 01:00:39 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2022-01-08 03:27:14 +00:00
|
|
|
"runtime"
|
2021-07-28 01:00:39 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2022-07-20 22:12:02 +00:00
|
|
|
"github.com/blang/semver"
|
2021-07-28 01:00:39 +00:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/pulumi/pulumi/pkg/v3/codegen"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/syntax"
|
2021-09-30 03:11:56 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/codegen/pcl"
|
2022-02-07 11:10:04 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/codegen/testing/utils"
|
2022-01-31 20:48:32 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
|
2022-07-20 22:12:02 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
|
2021-07-28 01:00:39 +00:00
|
|
|
)
|
|
|
|
|
2022-10-20 20:37:10 +00:00
|
|
|
const (
|
|
|
|
transpiledExamplesDir = "transpiled_examples"
|
|
|
|
)
|
|
|
|
|
|
|
|
func transpiled(dir string) string {
|
|
|
|
return filepath.Join(transpiledExamplesDir, dir)
|
|
|
|
}
|
|
|
|
|
2022-01-31 20:48:32 +00:00
|
|
|
var allProgLanguages = codegen.NewStringSet("dotnet", "python", "go", "nodejs")
|
|
|
|
|
2022-02-07 11:10:04 +00:00
|
|
|
type ProgramTest struct {
|
2022-10-11 10:56:29 +00:00
|
|
|
Directory string
|
|
|
|
Description string
|
|
|
|
Skip codegen.StringSet
|
|
|
|
ExpectNYIDiags codegen.StringSet
|
|
|
|
SkipCompile codegen.StringSet
|
2022-10-10 23:01:53 +00:00
|
|
|
BindOptions []pcl.BindOption
|
2022-10-11 10:56:29 +00:00
|
|
|
MockPluginVersions map[string]string
|
2021-07-28 01:00:39 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 11:10:04 +00:00
|
|
|
var testdataPath = filepath.Join("..", "testing", "test", "testdata")
|
2021-07-28 01:00:39 +00:00
|
|
|
|
2022-10-17 05:56:57 +00:00
|
|
|
// Get batch number k (base-1 indexed) of tests out of n batches total.
|
|
|
|
func ProgramTestBatch(k, n int) []ProgramTest {
|
|
|
|
start := ((k - 1) * len(PulumiPulumiProgramTests)) / n
|
|
|
|
end := ((k) * len(PulumiPulumiProgramTests)) / n
|
|
|
|
return PulumiPulumiProgramTests[start:end]
|
|
|
|
}
|
|
|
|
|
2023-07-28 18:30:00 +00:00
|
|
|
// Useful when debugging a single test case.
|
|
|
|
func SingleTestCase(directoryName string) []ProgramTest {
|
|
|
|
output := make([]ProgramTest, 0)
|
|
|
|
for _, t := range PulumiPulumiProgramTests {
|
|
|
|
if t.Directory == directoryName {
|
|
|
|
output = append(output, t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
2022-02-07 11:10:04 +00:00
|
|
|
var PulumiPulumiProgramTests = []ProgramTest{
|
2022-04-25 19:59:30 +00:00
|
|
|
{
|
|
|
|
Directory: "assets-archives",
|
|
|
|
Description: "Assets and archives",
|
|
|
|
},
|
2022-05-20 17:29:05 +00:00
|
|
|
{
|
|
|
|
Directory: "synthetic-resource-properties",
|
|
|
|
Description: "Synthetic resource properties",
|
|
|
|
SkipCompile: codegen.NewStringSet("nodejs", "dotnet", "go"), // not a real package
|
|
|
|
},
|
2021-07-28 01:00:39 +00:00
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "aws-s3-folder",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "AWS S3 Folder",
|
2022-11-28 19:26:32 +00:00
|
|
|
ExpectNYIDiags: codegen.NewStringSet("dotnet", "python"),
|
|
|
|
SkipCompile: codegen.NewStringSet("go", "python"),
|
2021-09-29 18:33:57 +00:00
|
|
|
// Blocked on python: TODO[pulumi/pulumi#8062]: Re-enable this test.
|
|
|
|
// Blocked on go:
|
|
|
|
// TODO[pulumi/pulumi#8064]
|
|
|
|
// TODO[pulumi/pulumi#8065]
|
2021-07-28 01:00:39 +00:00
|
|
|
},
|
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "aws-eks",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "AWS EKS",
|
|
|
|
},
|
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "aws-fargate",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "AWS Fargate",
|
|
|
|
},
|
2023-06-23 00:42:18 +00:00
|
|
|
{
|
|
|
|
Directory: "aws-fargate-output-versioned",
|
|
|
|
Description: "AWS Fargate Using Output-versioned invokes for python and typescript",
|
|
|
|
Skip: codegen.NewStringSet("go", "dotnet"),
|
|
|
|
BindOptions: []pcl.BindOption{pcl.PreferOutputVersionedInvokes},
|
|
|
|
},
|
2021-07-28 01:00:39 +00:00
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "aws-s3-logging",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "AWS S3 with logging",
|
2022-11-28 18:56:04 +00:00
|
|
|
SkipCompile: codegen.NewStringSet("go"),
|
2021-09-29 18:33:57 +00:00
|
|
|
// Blocked on nodejs: TODO[pulumi/pulumi#8068]
|
2021-11-15 20:17:20 +00:00
|
|
|
// Flaky in go: TODO[pulumi/pulumi#8123]
|
2021-07-28 01:00:39 +00:00
|
|
|
},
|
2022-07-06 13:27:17 +00:00
|
|
|
{
|
|
|
|
Directory: "aws-iam-policy",
|
|
|
|
Description: "AWS IAM Policy",
|
|
|
|
},
|
2023-11-23 00:26:41 +00:00
|
|
|
{
|
|
|
|
Directory: "read-file-func",
|
|
|
|
Description: "ReadFile function translation works",
|
|
|
|
},
|
2022-10-06 17:02:30 +00:00
|
|
|
{
|
|
|
|
Directory: "python-regress-10914",
|
|
|
|
Description: "Python regression test for #10914",
|
2022-10-07 12:02:12 +00:00
|
|
|
Skip: allProgLanguages.Except("python"),
|
2022-10-06 17:02:30 +00:00
|
|
|
},
|
2023-01-11 22:17:14 +00:00
|
|
|
{
|
|
|
|
Directory: "simplified-invokes",
|
|
|
|
Description: "Simplified invokes",
|
|
|
|
Skip: codegen.NewStringSet("python", "go"),
|
|
|
|
SkipCompile: codegen.NewStringSet("dotnet", "nodejs"),
|
|
|
|
},
|
[codegen/go] Improve optional params in invoke
As described in #8821, docs generated for helper functions can be incorrect because optional arguments to parameter objects are not correctly handled.
Previously, code would be generated like so:
```go
policyDocument, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
Statements: []iam.GetPolicyDocumentStatement{
iam.GetPolicyDocumentStatement{
Sid: "1",
//...
```
However "Sid" is of type `*string`.
This four helper conversion functions, to handle the primitive types we lower from, and modifies codegen to recursively apply these functions inside of an invoke call.
In the new code generation, the above is instead rendered as:
```go
policyDocument, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
Statements: []iam.GetPolicyDocumentStatement{
iam.GetPolicyDocumentStatement{
Sid: pulumi.StringRef("1"),
//...
```
2022-02-01 03:18:15 +00:00
|
|
|
{
|
|
|
|
Directory: "aws-optionals",
|
|
|
|
Description: "AWS get invoke with nested object constructor that takes an optional string",
|
2022-02-01 09:34:29 +00:00
|
|
|
// Testing Go behavior exclusively:
|
2022-02-01 19:41:01 +00:00
|
|
|
Skip: allProgLanguages.Except("go"),
|
[codegen/go] Improve optional params in invoke
As described in #8821, docs generated for helper functions can be incorrect because optional arguments to parameter objects are not correctly handled.
Previously, code would be generated like so:
```go
policyDocument, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
Statements: []iam.GetPolicyDocumentStatement{
iam.GetPolicyDocumentStatement{
Sid: "1",
//...
```
However "Sid" is of type `*string`.
This four helper conversion functions, to handle the primitive types we lower from, and modifies codegen to recursively apply these functions inside of an invoke call.
In the new code generation, the above is instead rendered as:
```go
policyDocument, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
Statements: []iam.GetPolicyDocumentStatement{
iam.GetPolicyDocumentStatement{
Sid: pulumi.StringRef("1"),
//...
```
2022-02-01 03:18:15 +00:00
|
|
|
},
|
2021-07-28 01:00:39 +00:00
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "aws-webserver",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "AWS Webserver",
|
|
|
|
},
|
2022-10-09 16:28:49 +00:00
|
|
|
{
|
|
|
|
Directory: "simple-range",
|
|
|
|
Description: "Simple range as int expression translation",
|
|
|
|
},
|
2021-07-28 01:00:39 +00:00
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "azure-native",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "Azure Native",
|
2022-09-28 00:15:10 +00:00
|
|
|
SkipCompile: codegen.NewStringSet("go", "nodejs", "dotnet"),
|
2021-09-29 18:33:57 +00:00
|
|
|
// Blocked on go:
|
|
|
|
// TODO[pulumi/pulumi#8073]
|
|
|
|
// TODO[pulumi/pulumi#8074]
|
|
|
|
// Blocked on nodejs:
|
|
|
|
// TODO[pulumi/pulumi#8075]
|
2021-07-28 01:00:39 +00:00
|
|
|
},
|
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "azure-sa",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "Azure SA",
|
|
|
|
},
|
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "kubernetes-operator",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "K8s Operator",
|
|
|
|
},
|
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "kubernetes-pod",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "K8s Pod",
|
2021-09-29 18:33:57 +00:00
|
|
|
SkipCompile: codegen.NewStringSet("go", "nodejs"),
|
|
|
|
// Blocked on go:
|
|
|
|
// TODO[pulumi/pulumi#8073]
|
|
|
|
// TODO[pulumi/pulumi#8074]
|
|
|
|
// Blocked on nodejs:
|
|
|
|
// TODO[pulumi/pulumi#8075]
|
2021-07-28 01:00:39 +00:00
|
|
|
},
|
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "kubernetes-template",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "K8s Template",
|
|
|
|
},
|
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "random-pet",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "Random Pet",
|
|
|
|
},
|
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "aws-secret",
|
2021-07-28 01:00:39 +00:00
|
|
|
Description: "Secret",
|
|
|
|
},
|
2021-07-29 03:41:23 +00:00
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "functions",
|
2021-07-29 03:41:23 +00:00
|
|
|
Description: "Functions",
|
|
|
|
},
|
2021-11-17 20:27:50 +00:00
|
|
|
{
|
2022-01-31 20:48:32 +00:00
|
|
|
Directory: "output-funcs-aws",
|
2021-11-17 20:27:50 +00:00
|
|
|
Description: "Output Versioned Functions",
|
|
|
|
},
|
2022-01-31 20:48:32 +00:00
|
|
|
{
|
|
|
|
Directory: "third-party-package",
|
|
|
|
Description: "Ensuring correct imports for third party packages",
|
|
|
|
// compiling and type checking involves downloading the real package to
|
|
|
|
// check against. Because we are checking against the "other" package
|
|
|
|
// (which doesn't exist), this does not work.
|
|
|
|
SkipCompile: codegen.NewStringSet("nodejs", "dotnet", "go"),
|
|
|
|
},
|
2022-02-08 13:45:24 +00:00
|
|
|
{
|
|
|
|
Directory: "invalid-go-sprintf",
|
|
|
|
Description: "Regress invalid Go",
|
|
|
|
Skip: codegen.NewStringSet("python", "nodejs", "dotnet"),
|
|
|
|
},
|
2022-04-07 10:00:19 +00:00
|
|
|
{
|
2022-04-18 09:03:42 +00:00
|
|
|
Directory: "typed-enum",
|
|
|
|
Description: "Supply strongly typed enums",
|
2022-08-16 10:38:10 +00:00
|
|
|
Skip: codegen.NewStringSet(golang),
|
2022-04-18 09:03:42 +00:00
|
|
|
},
|
2022-08-19 17:27:05 +00:00
|
|
|
{
|
|
|
|
Directory: "pulumi-stack-reference",
|
|
|
|
Description: "StackReference as resource",
|
|
|
|
},
|
2022-04-18 09:03:42 +00:00
|
|
|
{
|
2022-04-07 10:00:19 +00:00
|
|
|
Directory: "python-resource-names",
|
|
|
|
Description: "Repro for #9357",
|
|
|
|
Skip: codegen.NewStringSet("go", "nodejs", "dotnet"),
|
|
|
|
},
|
2022-04-25 22:07:25 +00:00
|
|
|
{
|
|
|
|
Directory: "logical-name",
|
|
|
|
Description: "Logical names",
|
|
|
|
},
|
2022-07-13 16:06:00 +00:00
|
|
|
{
|
|
|
|
Directory: "aws-lambda",
|
|
|
|
Description: "AWS Lambdas",
|
|
|
|
// We have special testing for this case because lambda is a python keyword.
|
|
|
|
Skip: codegen.NewStringSet("go", "nodejs", "dotnet"),
|
|
|
|
},
|
2022-09-14 04:18:07 +00:00
|
|
|
{
|
|
|
|
Directory: "discriminated-union",
|
|
|
|
Description: "Discriminated Unions for choosing an input type",
|
|
|
|
Skip: codegen.NewStringSet("go"),
|
|
|
|
// Blocked on go: TODO[pulumi/pulumi#10834]
|
|
|
|
},
|
2022-11-15 01:00:09 +00:00
|
|
|
{
|
|
|
|
Directory: "traverse-union-repro",
|
|
|
|
Description: `Handling the error "cannot traverse value of type union(...)"`,
|
|
|
|
BindOptions: []pcl.BindOption{
|
|
|
|
pcl.SkipResourceTypechecking,
|
|
|
|
pcl.AllowMissingVariables,
|
|
|
|
pcl.AllowMissingProperties,
|
|
|
|
},
|
|
|
|
// The example is known to be invalid. Specifically it hands a
|
|
|
|
// `[aws_subnet.test1.id]` to a `string` attribute, where `aws_subnet` is not in
|
|
|
|
// scope.
|
|
|
|
//
|
|
|
|
// The example is invalid in two ways:
|
|
|
|
// 1. `aws_subnet` is a missing variable.
|
|
|
|
// 2. `[...]` is a tuple, which can never be a string.
|
|
|
|
//
|
|
|
|
// Even though the generated code will not type check, it should still be
|
|
|
|
// directionally correct.
|
|
|
|
SkipCompile: allProgLanguages,
|
|
|
|
},
|
2023-03-08 13:21:34 +00:00
|
|
|
{
|
|
|
|
Directory: "components",
|
|
|
|
Description: "Components",
|
2023-04-05 11:19:52 +00:00
|
|
|
SkipCompile: codegen.NewStringSet("go"),
|
2023-03-08 13:21:34 +00:00
|
|
|
},
|
2023-04-05 11:04:46 +00:00
|
|
|
{
|
|
|
|
Directory: "entries-function",
|
|
|
|
Description: "Using the entries function",
|
2023-06-02 14:59:46 +00:00
|
|
|
// go and dotnet do fully not support GenForExpression yet
|
2023-04-05 11:04:46 +00:00
|
|
|
// Todo: https://github.com/pulumi/pulumi/issues/12606
|
|
|
|
SkipCompile: allProgLanguages.Except("nodejs").Except("python"),
|
|
|
|
},
|
2023-02-28 20:50:51 +00:00
|
|
|
{
|
|
|
|
Directory: "retain-on-delete",
|
|
|
|
Description: "Generate RetainOnDelete option",
|
|
|
|
},
|
2023-06-22 17:43:06 +00:00
|
|
|
{
|
|
|
|
Directory: "multiline-string",
|
|
|
|
Description: "Multiline string literals",
|
|
|
|
},
|
2023-06-23 17:38:13 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-11176",
|
|
|
|
Description: "Regression test for https://github.com/pulumi/pulumi/issues/11176",
|
|
|
|
Skip: allProgLanguages.Except("go"),
|
|
|
|
},
|
2023-03-10 11:14:28 +00:00
|
|
|
{
|
|
|
|
Directory: "throw-not-implemented",
|
2023-03-10 11:28:23 +00:00
|
|
|
Description: "Function notImplemented is compiled to a runtime error at call-site",
|
2023-03-10 11:14:28 +00:00
|
|
|
},
|
2023-03-16 14:41:04 +00:00
|
|
|
{
|
|
|
|
Directory: "python-reserved",
|
|
|
|
Description: "Test python reserved words aren't used",
|
|
|
|
Skip: allProgLanguages.Except("python"),
|
|
|
|
},
|
2023-04-21 10:18:23 +00:00
|
|
|
{
|
|
|
|
Directory: "iterating-optional-range-expressions",
|
|
|
|
Description: "Test that we can iterate over range expression that are option(iterator)",
|
2023-05-02 14:07:58 +00:00
|
|
|
// TODO: dotnet and go
|
|
|
|
Skip: allProgLanguages.Except("nodejs").Except("python"),
|
2023-04-26 18:00:32 +00:00
|
|
|
// We are using a synthetic schema defined in range-1.0.0.json so we can't compile all the way
|
|
|
|
SkipCompile: allProgLanguages,
|
2023-04-21 10:18:23 +00:00
|
|
|
},
|
2023-05-12 09:31:32 +00:00
|
|
|
{
|
|
|
|
Directory: "output-literals",
|
|
|
|
Description: "Tests that we can return various literal values via stack outputs",
|
|
|
|
SkipCompile: codegen.NewStringSet("go"),
|
|
|
|
},
|
2023-05-16 18:11:57 +00:00
|
|
|
{
|
|
|
|
Directory: "dynamic-entries",
|
|
|
|
Description: "Testing iteration of dynamic entries in TypeScript",
|
|
|
|
Skip: allProgLanguages.Except("nodejs"),
|
2023-05-16 19:33:14 +00:00
|
|
|
SkipCompile: allProgLanguages,
|
2023-05-16 18:11:57 +00:00
|
|
|
},
|
2023-05-25 20:12:13 +00:00
|
|
|
{
|
|
|
|
Directory: "single-or-none",
|
|
|
|
Description: "Tests using the singleOrNone function",
|
2023-06-11 09:05:10 +00:00
|
|
|
// TODO[pulumi/pulumi#4899]: Skip compiling for Go because it is trying to pass a value of type float64
|
|
|
|
// as an argument to ctx.Export but float64 does not implement pulumi.Input. The value needs to be
|
|
|
|
// wrapped as a pulumi.Float64.
|
|
|
|
SkipCompile: codegen.NewStringSet("go"),
|
2023-05-25 20:12:13 +00:00
|
|
|
},
|
2023-06-07 11:22:41 +00:00
|
|
|
{
|
|
|
|
Directory: "simple-splat",
|
|
|
|
Description: "An example that shows we can compile splat expressions from array of objects",
|
|
|
|
// Skip compiling because we are using a test schema without a corresponding real package
|
|
|
|
SkipCompile: allProgLanguages,
|
|
|
|
},
|
2023-06-02 16:33:18 +00:00
|
|
|
{
|
|
|
|
Directory: "invoke-inside-conditional-range",
|
|
|
|
Description: "Using the result of an invoke inside a conditional range expression of a resource",
|
2023-06-03 07:23:38 +00:00
|
|
|
Skip: allProgLanguages.Except("nodejs").Except("dotnet"),
|
2023-06-03 00:02:42 +00:00
|
|
|
SkipCompile: allProgLanguages,
|
2023-06-02 16:33:18 +00:00
|
|
|
},
|
2023-06-07 00:37:40 +00:00
|
|
|
{
|
|
|
|
Directory: "output-name-conflict",
|
|
|
|
Description: "Tests whether we are able to generate programs where output variables have same id as config var",
|
|
|
|
SkipCompile: codegen.NewStringSet("go"),
|
|
|
|
},
|
2023-06-08 23:44:09 +00:00
|
|
|
{
|
|
|
|
Directory: "snowflake-python-12998",
|
|
|
|
Description: "Tests regression for issue https://github.com/pulumi/pulumi/issues/12998",
|
|
|
|
Skip: allProgLanguages.Except("python"),
|
|
|
|
SkipCompile: allProgLanguages,
|
|
|
|
BindOptions: []pcl.BindOption{pcl.AllowMissingVariables, pcl.AllowMissingProperties},
|
|
|
|
},
|
2023-06-14 17:02:56 +00:00
|
|
|
{
|
|
|
|
Directory: "unknown-resource",
|
|
|
|
Description: "Tests generating code for unknown resources when skipping resource type-checking",
|
|
|
|
SkipCompile: allProgLanguages,
|
|
|
|
BindOptions: []pcl.BindOption{pcl.SkipResourceTypechecking},
|
|
|
|
},
|
2023-06-20 16:11:47 +00:00
|
|
|
{
|
|
|
|
Directory: "using-dashes",
|
|
|
|
Description: "Test program generation on packages with a dash in the name",
|
|
|
|
SkipCompile: allProgLanguages, // since we are using a synthetic schema
|
|
|
|
},
|
2023-07-10 13:05:18 +00:00
|
|
|
{
|
|
|
|
Directory: "unknown-invoke",
|
|
|
|
Description: "Tests generating code for unknown invokes when skipping invoke type checking",
|
|
|
|
SkipCompile: allProgLanguages,
|
|
|
|
BindOptions: []pcl.BindOption{pcl.SkipInvokeTypechecking},
|
|
|
|
},
|
2023-07-14 22:15:28 +00:00
|
|
|
{
|
|
|
|
Directory: "optional-complex-config",
|
|
|
|
Description: "Tests generating code for optional and complex config values",
|
2023-07-26 11:37:53 +00:00
|
|
|
Skip: allProgLanguages.Except("nodejs").Except("dotnet"),
|
|
|
|
SkipCompile: allProgLanguages.Except("nodejs").Except("dotnet"),
|
2023-07-14 22:15:28 +00:00
|
|
|
},
|
2023-07-18 06:47:37 +00:00
|
|
|
{
|
|
|
|
Directory: "interpolated-string-keys",
|
|
|
|
Description: "Tests that interpolated string keys are supported in maps. ",
|
|
|
|
Skip: allProgLanguages.Except("nodejs").Except("python"),
|
|
|
|
},
|
2023-08-07 19:08:54 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-node-12507",
|
|
|
|
Description: "Regression test for https://github.com/pulumi/pulumi/issues/12507",
|
|
|
|
Skip: allProgLanguages.Except("nodejs"),
|
|
|
|
BindOptions: []pcl.BindOption{pcl.PreferOutputVersionedInvokes},
|
|
|
|
},
|
2023-08-07 16:43:37 +00:00
|
|
|
{
|
|
|
|
Directory: "csharp-plain-lists",
|
|
|
|
Description: "Tests that plain lists are supported in C#",
|
|
|
|
Skip: allProgLanguages.Except("dotnet"),
|
|
|
|
},
|
2023-07-28 18:30:00 +00:00
|
|
|
{
|
|
|
|
Directory: "csharp-typed-for-expressions",
|
|
|
|
Description: "Testing for expressions with typed target expressions in csharp",
|
|
|
|
Skip: allProgLanguages.Except("dotnet"),
|
|
|
|
},
|
2023-09-28 12:43:35 +00:00
|
|
|
{
|
|
|
|
Directory: "empty-list-property",
|
|
|
|
Description: "Tests compiling empty list expressions of object properties",
|
|
|
|
},
|
2023-10-06 22:26:04 +00:00
|
|
|
{
|
|
|
|
Directory: "python-regress-14037",
|
|
|
|
Description: "Regression test for rewriting qoutes in python",
|
|
|
|
Skip: allProgLanguages.Except("python"),
|
|
|
|
},
|
2023-11-03 14:22:43 +00:00
|
|
|
{
|
|
|
|
Directory: "inline-invokes",
|
|
|
|
Description: "Tests whether using inline invoke expressions works",
|
|
|
|
SkipCompile: codegen.NewStringSet("go"),
|
|
|
|
},
|
2022-10-27 18:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var PulumiPulumiYAMLProgramTests = []ProgramTest{
|
2022-10-20 20:37:10 +00:00
|
|
|
// PCL files from pulumi/yaml transpiled examples
|
|
|
|
{
|
|
|
|
Directory: transpiled("aws-eks"),
|
|
|
|
Description: "AWS EKS",
|
|
|
|
Skip: codegen.NewStringSet("go", "nodejs", "dotnet"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("aws-static-website"),
|
|
|
|
Description: "AWS static website",
|
|
|
|
Skip: codegen.NewStringSet("go", "nodejs", "dotnet"),
|
2022-11-16 01:44:21 +00:00
|
|
|
BindOptions: []pcl.BindOption{pcl.SkipResourceTypechecking},
|
2022-10-20 20:37:10 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("awsx-fargate"),
|
|
|
|
Description: "AWSx Fargate",
|
2022-10-27 18:01:05 +00:00
|
|
|
Skip: codegen.NewStringSet("dotnet", "nodejs", "go"),
|
2022-10-20 20:37:10 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("azure-app-service"),
|
|
|
|
Description: "Azure App Service",
|
|
|
|
Skip: codegen.NewStringSet("go", "dotnet"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("azure-container-apps"),
|
|
|
|
Description: "Azure Container Apps",
|
|
|
|
Skip: codegen.NewStringSet("go", "nodejs", "dotnet", "python"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("azure-static-website"),
|
|
|
|
Description: "Azure static website",
|
|
|
|
Skip: codegen.NewStringSet("go", "nodejs", "dotnet", "python"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("cue-eks"),
|
|
|
|
Description: "Cue EKS",
|
|
|
|
Skip: codegen.NewStringSet("go", "nodejs", "dotnet"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("cue-random"),
|
|
|
|
Description: "Cue random",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("getting-started"),
|
|
|
|
Description: "Getting started",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("kubernetes"),
|
|
|
|
Description: "Kubernetes",
|
|
|
|
Skip: codegen.NewStringSet("go"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("pulumi-variable"),
|
|
|
|
Description: "Pulumi variable",
|
|
|
|
Skip: codegen.NewStringSet("go", "nodejs", "dotnet"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("random"),
|
|
|
|
Description: "Random",
|
|
|
|
Skip: codegen.NewStringSet("nodejs"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("readme"),
|
|
|
|
Description: "README",
|
|
|
|
Skip: codegen.NewStringSet("go", "dotnet"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("stackreference-consumer"),
|
|
|
|
Description: "Stack reference consumer",
|
|
|
|
Skip: codegen.NewStringSet("go", "nodejs", "dotnet"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("stackreference-producer"),
|
|
|
|
Description: "Stack reference producer",
|
|
|
|
Skip: codegen.NewStringSet("go", "dotnet"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("webserver-json"),
|
|
|
|
Description: "Webserver JSON",
|
|
|
|
Skip: codegen.NewStringSet("go", "dotnet", "python"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: transpiled("webserver"),
|
|
|
|
Description: "Webserver",
|
|
|
|
Skip: codegen.NewStringSet("go", "dotnet", "python"),
|
|
|
|
},
|
2021-07-28 01:00:39 +00:00
|
|
|
}
|
|
|
|
|
2021-09-29 18:33:57 +00:00
|
|
|
// Checks that a generated program is correct
|
2021-10-19 19:17:19 +00:00
|
|
|
//
|
|
|
|
// The arguments are to be read:
|
|
|
|
// (Testing environment, path to generated code, set of dependencies)
|
|
|
|
type CheckProgramOutput = func(*testing.T, string, codegen.StringSet)
|
2021-09-29 18:33:57 +00:00
|
|
|
|
2021-09-30 03:11:56 +00:00
|
|
|
// Generates a program from a pcl.Program
|
|
|
|
type GenProgram = func(program *pcl.Program) (map[string][]byte, hcl.Diagnostics, error)
|
2021-09-29 18:33:57 +00:00
|
|
|
|
2022-07-20 22:12:02 +00:00
|
|
|
// Generates a project from a pcl.Program
|
2023-08-03 10:40:05 +00:00
|
|
|
type GenProject = func(
|
|
|
|
directory string, project workspace.Project,
|
|
|
|
program *pcl.Program, localDependencies map[string]string,
|
|
|
|
) error
|
2022-07-20 22:12:02 +00:00
|
|
|
|
2021-10-19 19:17:19 +00:00
|
|
|
type ProgramCodegenOptions struct {
|
2021-09-29 18:33:57 +00:00
|
|
|
Language string
|
|
|
|
Extension string
|
|
|
|
OutputFile string
|
|
|
|
Check CheckProgramOutput
|
|
|
|
GenProgram GenProgram
|
2022-02-07 11:10:04 +00:00
|
|
|
TestCases []ProgramTest
|
2022-07-20 22:12:02 +00:00
|
|
|
|
|
|
|
// For generating a full project
|
|
|
|
IsGenProject bool
|
|
|
|
GenProject GenProject
|
|
|
|
// Maps a test file (i.e. "aws-resource-options") to a struct containing a package
|
|
|
|
// (i.e. "github.com/pulumi/pulumi-aws/sdk/v5", "pulumi-aws) and its
|
|
|
|
// version prefixed by an operator (i.e. " v5.11.0", ==5.11.0")
|
|
|
|
ExpectedVersion map[string]PkgVersionInfo
|
|
|
|
DependencyFile string
|
|
|
|
}
|
|
|
|
|
|
|
|
type PkgVersionInfo struct {
|
|
|
|
Pkg string
|
|
|
|
OpAndVersion string
|
2021-07-28 01:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestProgramCodegen runs the complete set of program code generation tests against a particular
|
|
|
|
// language's code generator.
|
|
|
|
//
|
|
|
|
// A program code generation test consists of a PCL file (.pp extension) and a set of expected outputs
|
|
|
|
// for each language.
|
|
|
|
//
|
|
|
|
// The PCL file is the only piece that must be manually authored. Once the schema has been written, the expected outputs
|
|
|
|
// can be generated by running `PULUMI_ACCEPT=true go test ./..." from the `pkg/codegen` directory.
|
2023-01-06 00:07:45 +00:00
|
|
|
//
|
|
|
|
//nolint:revive
|
2021-07-28 01:00:39 +00:00
|
|
|
func TestProgramCodegen(
|
|
|
|
t *testing.T,
|
2021-10-19 19:17:19 +00:00
|
|
|
testcase ProgramCodegenOptions,
|
2021-07-28 01:00:39 +00:00
|
|
|
) {
|
2022-01-08 03:27:14 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
t.Skip("TestProgramCodegen is skipped on Windows")
|
|
|
|
}
|
|
|
|
|
2022-02-07 11:10:04 +00:00
|
|
|
assert.NotNil(t, testcase.TestCases, "Caller must provide test cases")
|
2022-01-31 20:48:32 +00:00
|
|
|
pulumiAccept := cmdutil.IsTruthy(os.Getenv("PULUMI_ACCEPT"))
|
2022-05-23 22:44:35 +00:00
|
|
|
skipCompile := cmdutil.IsTruthy(os.Getenv("PULUMI_SKIP_COMPILE_TEST"))
|
2022-10-20 20:37:10 +00:00
|
|
|
|
2022-02-07 11:10:04 +00:00
|
|
|
for _, tt := range testcase.TestCases {
|
2022-03-04 08:17:41 +00:00
|
|
|
tt := tt // avoid capturing loop variable
|
2022-09-08 16:45:15 +00:00
|
|
|
t.Run(tt.Directory, func(t *testing.T) {
|
2023-01-20 00:03:45 +00:00
|
|
|
// These tests should not run in parallel.
|
|
|
|
// They take up a fair bit of memory
|
|
|
|
// and can OOM in CI with too many running.
|
|
|
|
|
2021-09-29 18:33:57 +00:00
|
|
|
var err error
|
|
|
|
if tt.Skip.Has(testcase.Language) {
|
2021-07-28 01:00:39 +00:00
|
|
|
t.Skip()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-29 18:33:57 +00:00
|
|
|
expectNYIDiags := tt.ExpectNYIDiags.Has(testcase.Language)
|
2021-07-28 01:00:39 +00:00
|
|
|
|
2022-01-31 20:48:32 +00:00
|
|
|
testDir := filepath.Join(testdataPath, tt.Directory+"-pp")
|
|
|
|
pclFile := filepath.Join(testDir, tt.Directory+".pp")
|
2022-10-20 20:37:10 +00:00
|
|
|
if strings.HasPrefix(tt.Directory, transpiledExamplesDir) {
|
|
|
|
pclFile = filepath.Join(testDir, filepath.Base(tt.Directory)+".pp")
|
|
|
|
}
|
2021-09-29 18:33:57 +00:00
|
|
|
testDir = filepath.Join(testDir, testcase.Language)
|
2023-03-03 16:36:39 +00:00
|
|
|
err = os.MkdirAll(testDir, 0o700)
|
2021-09-29 18:33:57 +00:00
|
|
|
if err != nil && !os.IsExist(err) {
|
|
|
|
t.Fatalf("Failed to create %q: %s", testDir, err)
|
2021-07-28 01:00:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-20 20:37:10 +00:00
|
|
|
contents, err := os.ReadFile(pclFile)
|
2021-07-28 01:00:39 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not read %v: %v", pclFile, err)
|
|
|
|
}
|
|
|
|
|
2022-01-31 20:48:32 +00:00
|
|
|
expectedFile := filepath.Join(testDir, tt.Directory+"."+testcase.Extension)
|
2022-10-20 20:37:10 +00:00
|
|
|
if strings.HasPrefix(tt.Directory, transpiledExamplesDir) {
|
|
|
|
expectedFile = filepath.Join(testDir, filepath.Base(tt.Directory)+"."+testcase.Extension)
|
|
|
|
}
|
|
|
|
expected, err := os.ReadFile(expectedFile)
|
2022-01-31 20:48:32 +00:00
|
|
|
if err != nil && !pulumiAccept {
|
2021-07-28 01:00:39 +00:00
|
|
|
t.Fatalf("could not read %v: %v", expectedFile, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
parser := syntax.NewParser()
|
2022-01-31 20:48:32 +00:00
|
|
|
err = parser.ParseFile(bytes.NewReader(contents), tt.Directory+".pp")
|
2021-07-28 01:00:39 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not read %v: %v", pclFile, err)
|
|
|
|
}
|
|
|
|
if parser.Diagnostics.HasErrors() {
|
|
|
|
t.Fatalf("failed to parse files: %v", parser.Diagnostics)
|
|
|
|
}
|
|
|
|
|
2022-11-15 01:00:09 +00:00
|
|
|
hclFiles := map[string]*hcl.File{
|
2023-03-03 16:36:39 +00:00
|
|
|
tt.Directory + ".pp": {Body: parser.Files[0].Body, Bytes: parser.Files[0].Bytes},
|
|
|
|
}
|
2022-11-15 01:00:09 +00:00
|
|
|
opts := append(tt.BindOptions, pcl.PluginHost(utils.NewHost(testdataPath)))
|
2023-03-08 13:21:34 +00:00
|
|
|
rootProgramPath := filepath.Join(testdataPath, tt.Directory+"-pp")
|
|
|
|
absoluteProgramPath, err := filepath.Abs(rootProgramPath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to bind program: unable to find the absolute path of %v", rootProgramPath)
|
|
|
|
}
|
|
|
|
opts = append(opts, pcl.DirPath(absoluteProgramPath))
|
|
|
|
opts = append(opts, pcl.ComponentBinder(pcl.ComponentProgramBinderFromFileSystem()))
|
2022-10-11 10:56:29 +00:00
|
|
|
|
|
|
|
program, diags, err := pcl.BindProgram(parser.Files, opts...)
|
2021-07-28 01:00:39 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not bind program: %v", err)
|
|
|
|
}
|
2022-11-15 01:00:09 +00:00
|
|
|
bindDiags := new(bytes.Buffer)
|
|
|
|
if len(diags) > 0 {
|
|
|
|
require.NoError(t, hcl.NewDiagnosticTextWriter(bindDiags, hclFiles, 80, false).WriteDiagnostics(diags))
|
|
|
|
if diags.HasErrors() {
|
|
|
|
t.Fatalf("failed to bind program:\n%s", bindDiags)
|
|
|
|
}
|
|
|
|
t.Logf("bind diags:\n%s", bindDiags)
|
2021-07-28 01:00:39 +00:00
|
|
|
}
|
2022-07-20 22:12:02 +00:00
|
|
|
var files map[string][]byte
|
|
|
|
// generate a full project and check expected package versions
|
|
|
|
if testcase.IsGenProject {
|
|
|
|
project := workspace.Project{
|
|
|
|
Name: "test",
|
|
|
|
Runtime: workspace.NewProjectRuntimeInfo(testcase.Language, nil),
|
|
|
|
}
|
2023-08-03 10:40:05 +00:00
|
|
|
err = testcase.GenProject(testDir, project, program, nil /*localDependencies*/)
|
2022-07-20 22:12:02 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
depFilePath := filepath.Join(testDir, testcase.DependencyFile)
|
|
|
|
outfilePath := filepath.Join(testDir, testcase.OutputFile)
|
|
|
|
CheckVersion(t, tt.Directory, depFilePath, testcase.ExpectedVersion)
|
|
|
|
GenProjectCleanUp(t, testDir, depFilePath, outfilePath)
|
|
|
|
|
|
|
|
}
|
|
|
|
files, diags, err = testcase.GenProgram(program)
|
2021-07-28 01:00:39 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
if expectNYIDiags {
|
|
|
|
var tmpDiags hcl.Diagnostics
|
|
|
|
for _, d := range diags {
|
|
|
|
if !strings.HasPrefix(d.Summary, "not yet implemented") {
|
|
|
|
tmpDiags = append(tmpDiags, d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
diags = tmpDiags
|
|
|
|
}
|
|
|
|
if diags.HasErrors() {
|
2022-11-15 01:00:09 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
|
|
|
err := hcl.NewDiagnosticTextWriter(buf, hclFiles, 80, false).WriteDiagnostics(diags)
|
|
|
|
require.NoError(t, err, "Failed to write diag")
|
|
|
|
|
|
|
|
t.Fatalf("failed to generate program:\n%s", buf)
|
2021-07-28 01:00:39 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 20:48:32 +00:00
|
|
|
if pulumiAccept {
|
2023-03-03 16:36:39 +00:00
|
|
|
err := os.WriteFile(expectedFile, files[testcase.OutputFile], 0o600)
|
2021-07-28 01:00:39 +00:00
|
|
|
require.NoError(t, err)
|
2023-03-08 13:21:34 +00:00
|
|
|
// generate the rest of the files
|
|
|
|
for fileName, content := range files {
|
|
|
|
if fileName != testcase.OutputFile {
|
|
|
|
outputPath := filepath.Join(testDir, fileName)
|
|
|
|
err := os.WriteFile(outputPath, content, 0o600)
|
|
|
|
require.NoError(t, err, "Failed to write file %s", outputPath)
|
|
|
|
}
|
|
|
|
}
|
2021-09-29 18:33:57 +00:00
|
|
|
} else {
|
|
|
|
assert.Equal(t, string(expected), string(files[testcase.OutputFile]))
|
2023-03-08 13:21:34 +00:00
|
|
|
// assert that the content is correct for the rest of the files
|
|
|
|
for fileName, content := range files {
|
|
|
|
if fileName != testcase.OutputFile {
|
|
|
|
outputPath := filepath.Join(testDir, fileName)
|
|
|
|
outputContent, err := os.ReadFile(outputPath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, string(outputContent), string(content))
|
|
|
|
}
|
|
|
|
}
|
2021-09-29 18:33:57 +00:00
|
|
|
}
|
2022-05-23 22:44:35 +00:00
|
|
|
if !skipCompile && testcase.Check != nil && !tt.SkipCompile.Has(testcase.Language) {
|
2021-10-19 19:17:19 +00:00
|
|
|
extraPulumiPackages := codegen.NewStringSet()
|
2023-03-08 13:21:34 +00:00
|
|
|
collectExtraPulumiPackages(program, extraPulumiPackages)
|
2021-10-19 19:17:19 +00:00
|
|
|
testcase.Check(t, expectedFile, extraPulumiPackages)
|
2021-07-28 01:00:39 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-07-20 22:12:02 +00:00
|
|
|
|
2023-03-08 13:21:34 +00:00
|
|
|
func collectExtraPulumiPackages(program *pcl.Program, extraPulumiPackages codegen.StringSet) {
|
|
|
|
for _, n := range program.Nodes {
|
|
|
|
if r, isResource := n.(*pcl.Resource); isResource {
|
|
|
|
pkg, _, _, _ := r.DecomposeToken()
|
|
|
|
if pkg != "pulumi" {
|
|
|
|
extraPulumiPackages.Add(pkg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if component, isComponent := n.(*pcl.Component); isComponent {
|
|
|
|
collectExtraPulumiPackages(component.Program, extraPulumiPackages)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-20 22:12:02 +00:00
|
|
|
// CheckVersion checks for an expected package version
|
|
|
|
// Todo: support checking multiple package expected versions
|
|
|
|
func CheckVersion(t *testing.T, dir, depFilePath string, expectedVersionMap map[string]PkgVersionInfo) {
|
|
|
|
depFile, err := os.Open(depFilePath)
|
|
|
|
require.NoError(t, err)
|
2022-10-10 23:01:53 +00:00
|
|
|
defer depFile.Close()
|
2022-07-20 22:12:02 +00:00
|
|
|
|
|
|
|
// Splits on newlines by default.
|
|
|
|
scanner := bufio.NewScanner(depFile)
|
|
|
|
|
|
|
|
match := false
|
|
|
|
expectedPkg, expectedVersion := strings.TrimSpace(expectedVersionMap[dir].Pkg),
|
|
|
|
strings.TrimSpace(expectedVersionMap[dir].OpAndVersion)
|
|
|
|
for scanner.Scan() {
|
|
|
|
line := scanner.Text()
|
|
|
|
if strings.Contains(line, expectedPkg) {
|
|
|
|
line = strings.TrimSpace(line)
|
|
|
|
actualVersion := strings.TrimPrefix(line, expectedPkg)
|
|
|
|
actualVersion = strings.TrimSpace(actualVersion)
|
|
|
|
expectedVersion = strings.Trim(expectedVersion, "v:^/> ")
|
|
|
|
actualVersion = strings.Trim(actualVersion, "v:^/> ")
|
|
|
|
if expectedVersion == actualVersion {
|
|
|
|
match = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
actualSemver, err := semver.Make(actualVersion)
|
|
|
|
if err == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
expectedSemver, _ := semver.Make(expectedVersion)
|
|
|
|
if actualSemver.Compare(expectedSemver) >= 0 {
|
|
|
|
match = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-10 23:01:53 +00:00
|
|
|
require.Truef(t, match, "Did not find expected package version pair (%q,%q). Searched in:\n%s",
|
|
|
|
expectedPkg, expectedVersion, newLazyStringer(func() string {
|
|
|
|
// Reset the read on the file
|
|
|
|
_, err := depFile.Seek(0, io.SeekStart)
|
|
|
|
require.NoError(t, err)
|
|
|
|
buf := new(strings.Builder)
|
|
|
|
_, err = io.Copy(buf, depFile)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return buf.String()
|
|
|
|
}).String())
|
2022-07-20 22:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GenProjectCleanUp(t *testing.T, dir, depFilePath, outfilePath string) {
|
|
|
|
os.Remove(depFilePath)
|
|
|
|
os.Remove(outfilePath)
|
|
|
|
os.Remove(dir + "/.gitignore")
|
|
|
|
os.Remove(dir + "/Pulumi.yaml")
|
|
|
|
}
|
2022-10-10 23:01:53 +00:00
|
|
|
|
|
|
|
type lazyStringer struct {
|
|
|
|
cache string
|
|
|
|
f func() string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l lazyStringer) String() string {
|
|
|
|
if l.cache == "" {
|
|
|
|
l.cache = l.f()
|
|
|
|
}
|
|
|
|
return l.cache
|
|
|
|
}
|
|
|
|
|
|
|
|
// The `fmt` `%s` calls .String() if the object is not a string itself. We can delay
|
|
|
|
// computing expensive display logic until and unless we actually will use it.
|
|
|
|
func newLazyStringer(f func() string) fmt.Stringer {
|
|
|
|
return lazyStringer{f: f}
|
|
|
|
}
|