2021-07-06 22:40:53 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
2021-09-28 14:33:14 +00:00
|
|
|
"flag"
|
2021-07-13 23:41:40 +00:00
|
|
|
"os"
|
2021-07-06 22:40:53 +00:00
|
|
|
"path/filepath"
|
2022-01-08 03:27:14 +00:00
|
|
|
"runtime"
|
2021-09-22 17:55:20 +00:00
|
|
|
"sort"
|
2021-12-10 23:35:24 +00:00
|
|
|
"strconv"
|
2021-09-22 17:55:20 +00:00
|
|
|
"strings"
|
2022-03-04 08:17:41 +00:00
|
|
|
"sync"
|
2021-07-06 22:40:53 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-07-27 02:23:17 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-09-15 16:49:36 +00:00
|
|
|
|
|
|
|
"github.com/pulumi/pulumi/pkg/v3/codegen"
|
2021-07-06 22:40:53 +00:00
|
|
|
)
|
|
|
|
|
2021-09-22 17:55:20 +00:00
|
|
|
// Defines an extra check logic that accepts the directory with the
|
|
|
|
// generated code, typically `$TestDir/$test.Directory/$language`.
|
|
|
|
type CodegenCheck func(t *testing.T, codedir string)
|
2021-07-27 02:23:17 +00:00
|
|
|
|
2022-02-07 11:10:04 +00:00
|
|
|
type SDKTest struct {
|
2021-09-22 17:55:20 +00:00
|
|
|
Directory string
|
|
|
|
Description string
|
|
|
|
|
|
|
|
// Extra checks for this test. They keys of this map
|
|
|
|
// are of the form "$language/$check" such as "go/compile".
|
|
|
|
Checks map[string]CodegenCheck
|
|
|
|
|
|
|
|
// Skip checks, identified by "$language/$check".
|
2021-12-08 05:21:04 +00:00
|
|
|
// "$language/any" is special, skipping generating the
|
|
|
|
// code as well as all tests.
|
2021-09-22 17:55:20 +00:00
|
|
|
Skip codegen.StringSet
|
|
|
|
|
|
|
|
// Do not compile the generated code for the languages in this set.
|
|
|
|
// This is a helper form of `Skip`.
|
2021-09-15 16:49:36 +00:00
|
|
|
SkipCompileCheck codegen.StringSet
|
2022-03-04 08:17:41 +00:00
|
|
|
|
|
|
|
// Mutex to ensure only a single test operates on directory at a time
|
|
|
|
Mutex sync.Mutex
|
2021-07-06 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-21 20:58:11 +00:00
|
|
|
// ShouldSkipTest indicates if a given test for a given language should be run.
|
2022-03-04 08:17:41 +00:00
|
|
|
func (tt *SDKTest) ShouldSkipTest(language, test string) bool {
|
2022-01-21 20:58:11 +00:00
|
|
|
// Only language-specific checks.
|
|
|
|
if !strings.HasPrefix(test, language+"/") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obey SkipCompileCheck to skip compile and test targets.
|
|
|
|
if tt.SkipCompileCheck != nil &&
|
|
|
|
tt.SkipCompileCheck.Has(language) &&
|
2023-12-12 12:19:42 +00:00
|
|
|
(test == language+"/compile" ||
|
|
|
|
test == language+"/test") {
|
2022-01-21 20:58:11 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obey Skip.
|
|
|
|
if tt.Skip != nil && tt.Skip.Has(test) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// ShouldSkipCodegen determines if codegen should be run. ShouldSkipCodegen=true
|
|
|
|
// further implies no other tests will be run.
|
2022-03-04 08:17:41 +00:00
|
|
|
func (tt *SDKTest) ShouldSkipCodegen(language string) bool {
|
2022-01-21 20:58:11 +00:00
|
|
|
return tt.Skip.Has(language + "/any")
|
|
|
|
}
|
|
|
|
|
2021-09-15 16:49:36 +00:00
|
|
|
const (
|
2021-10-07 19:39:19 +00:00
|
|
|
python = "python"
|
2021-09-15 16:49:36 +00:00
|
|
|
nodejs = "nodejs"
|
|
|
|
dotnet = "dotnet"
|
|
|
|
golang = "go"
|
|
|
|
)
|
|
|
|
|
2022-01-21 20:58:11 +00:00
|
|
|
var allLanguages = codegen.NewStringSet("python/any", "nodejs/any", "dotnet/any", "go/any", "docs/any")
|
|
|
|
|
2022-03-04 08:17:41 +00:00
|
|
|
var PulumiPulumiSDKTests = []*SDKTest{
|
2021-09-04 02:42:45 +00:00
|
|
|
{
|
2021-09-23 22:42:48 +00:00
|
|
|
Directory: "naming-collisions",
|
2022-12-09 12:57:00 +00:00
|
|
|
Description: "Schema with types that could potentially produce collisions.",
|
2021-09-04 02:42:45 +00:00
|
|
|
},
|
2021-08-10 05:58:24 +00:00
|
|
|
{
|
2021-09-23 22:42:48 +00:00
|
|
|
Directory: "dash-named-schema",
|
|
|
|
Description: "Simple schema with a two part name (foo-bar)",
|
2021-08-10 05:58:24 +00:00
|
|
|
},
|
2021-07-06 22:40:53 +00:00
|
|
|
{
|
2021-09-15 16:49:36 +00:00
|
|
|
Directory: "external-resource-schema",
|
|
|
|
Description: "External resource schema",
|
2022-01-28 21:28:55 +00:00
|
|
|
SkipCompileCheck: codegen.NewStringSet(golang),
|
2021-07-06 22:40:53 +00:00
|
|
|
},
|
|
|
|
{
|
2023-10-20 22:21:58 +00:00
|
|
|
Directory: "nested-module",
|
|
|
|
Description: "Nested module",
|
2021-07-06 22:40:53 +00:00
|
|
|
},
|
2023-01-11 22:17:14 +00:00
|
|
|
{
|
|
|
|
Directory: "simplified-invokes",
|
|
|
|
Description: "Simplified invokes",
|
|
|
|
Skip: codegen.NewStringSet("python/any", "go/any"),
|
|
|
|
},
|
2021-07-06 22:40:53 +00:00
|
|
|
{
|
2023-10-20 22:21:58 +00:00
|
|
|
Directory: "nested-module-thirdparty",
|
|
|
|
Description: "Third-party nested module",
|
2021-07-06 22:40:53 +00:00
|
|
|
},
|
|
|
|
{
|
2021-09-23 21:31:17 +00:00
|
|
|
Directory: "plain-schema-gh6957",
|
|
|
|
Description: "Repro for #6957",
|
2021-07-06 22:40:53 +00:00
|
|
|
},
|
2021-09-22 03:48:45 +00:00
|
|
|
{
|
2021-09-23 21:31:17 +00:00
|
|
|
Directory: "resource-args-python-case-insensitive",
|
|
|
|
Description: "Resource args with same named resource and type case insensitive",
|
2021-09-22 03:48:45 +00:00
|
|
|
},
|
2021-07-06 22:40:53 +00:00
|
|
|
{
|
2021-09-23 21:31:17 +00:00
|
|
|
Directory: "resource-args-python",
|
|
|
|
Description: "Resource args with same named resource and type",
|
2021-07-06 22:40:53 +00:00
|
|
|
},
|
|
|
|
{
|
2021-09-23 21:31:17 +00:00
|
|
|
Directory: "simple-enum-schema",
|
|
|
|
Description: "Simple schema with enum types",
|
2021-07-06 22:40:53 +00:00
|
|
|
},
|
|
|
|
{
|
2021-09-23 21:31:17 +00:00
|
|
|
Directory: "simple-plain-schema",
|
|
|
|
Description: "Simple schema with plain properties",
|
2021-07-06 22:40:53 +00:00
|
|
|
},
|
|
|
|
{
|
2021-09-23 21:31:17 +00:00
|
|
|
Directory: "simple-plain-schema-with-root-package",
|
|
|
|
Description: "Simple schema with root package set",
|
2021-07-06 22:40:53 +00:00
|
|
|
},
|
2023-05-02 15:48:45 +00:00
|
|
|
{
|
|
|
|
Directory: "simple-schema-pyproject",
|
|
|
|
Description: "A simple schema that generates a pyproject.toml file",
|
2023-05-26 18:28:10 +00:00
|
|
|
Skip: codegen.NewStringSet("go/any", "nodejs/any", "dotnet/any"),
|
2023-05-02 15:48:45 +00:00
|
|
|
},
|
2021-07-06 22:40:53 +00:00
|
|
|
{
|
2021-09-23 21:31:17 +00:00
|
|
|
Directory: "simple-resource-schema",
|
|
|
|
Description: "Simple schema with local resource properties",
|
2021-07-06 22:40:53 +00:00
|
|
|
},
|
|
|
|
{
|
2021-09-23 21:31:17 +00:00
|
|
|
Directory: "simple-resource-schema-custom-pypackage-name",
|
|
|
|
Description: "Simple schema with local resource properties and custom Python package name",
|
2021-07-06 22:40:53 +00:00
|
|
|
},
|
2021-07-08 20:54:03 +00:00
|
|
|
{
|
2021-09-15 16:49:36 +00:00
|
|
|
Directory: "simple-methods-schema",
|
|
|
|
Description: "Simple schema with methods",
|
2021-10-18 22:18:15 +00:00
|
|
|
SkipCompileCheck: codegen.NewStringSet(nodejs, golang),
|
2021-07-08 20:54:03 +00:00
|
|
|
},
|
2021-10-01 18:33:02 +00:00
|
|
|
{
|
|
|
|
Directory: "simple-methods-schema-single-value-returns",
|
|
|
|
Description: "Simple schema with methods that return single values",
|
|
|
|
},
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
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. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] 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. -->
2023-11-18 06:02:06 +00:00
|
|
|
{
|
|
|
|
Directory: "methods-return-plain-resource",
|
|
|
|
Description: "Test returning plain Resource objects from methods",
|
|
|
|
Skip: codegen.NewStringSet("dotnet/any"),
|
|
|
|
},
|
2021-07-13 23:41:40 +00:00
|
|
|
{
|
2021-09-23 21:31:17 +00:00
|
|
|
Directory: "simple-yaml-schema",
|
|
|
|
Description: "Simple schema encoded using YAML",
|
2021-07-13 23:41:40 +00:00
|
|
|
},
|
2021-07-14 21:26:50 +00:00
|
|
|
{
|
2022-11-30 06:53:16 +00:00
|
|
|
Directory: "provider-config-schema",
|
|
|
|
Description: "Simple provider config schema",
|
|
|
|
// For golang skip check, see https://github.com/pulumi/pulumi/issues/11567
|
|
|
|
SkipCompileCheck: codegen.NewStringSet(dotnet, golang),
|
2021-09-15 16:49:36 +00:00
|
|
|
},
|
|
|
|
{
|
2022-02-26 22:26:16 +00:00
|
|
|
Directory: "replace-on-change",
|
|
|
|
Description: "Simple use of replaceOnChange in schema",
|
2021-07-14 21:26:50 +00:00
|
|
|
},
|
2023-11-21 22:40:14 +00:00
|
|
|
{
|
|
|
|
Directory: "simple-resource-with-aliases",
|
|
|
|
Description: "Simple schema with a resource that has aliases",
|
|
|
|
},
|
2021-09-08 05:23:30 +00:00
|
|
|
{
|
2021-09-15 16:49:36 +00:00
|
|
|
Directory: "resource-property-overlap",
|
2021-09-28 14:33:14 +00:00
|
|
|
Description: "A resource with the same name as its property",
|
2021-09-15 16:49:36 +00:00
|
|
|
SkipCompileCheck: codegen.NewStringSet(dotnet, nodejs),
|
2021-09-08 05:23:30 +00:00
|
|
|
},
|
2021-09-20 17:11:44 +00:00
|
|
|
{
|
2021-09-23 21:31:17 +00:00
|
|
|
Directory: "hyphen-url",
|
2021-09-28 14:33:14 +00:00
|
|
|
Description: "A resource url with a hyphen in its path",
|
2022-08-16 10:38:10 +00:00
|
|
|
Skip: codegen.NewStringSet("go/any"),
|
2021-09-23 17:42:20 +00:00
|
|
|
},
|
|
|
|
{
|
2021-10-07 19:39:19 +00:00
|
|
|
Directory: "output-funcs",
|
|
|
|
Description: "Tests targeting the $fn_output helper code generation feature",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: "output-funcs-edgeorder",
|
|
|
|
Description: "Regresses Node compilation issues on a subset of azure-native",
|
2021-12-02 01:53:18 +00:00
|
|
|
SkipCompileCheck: codegen.NewStringSet(golang, python),
|
2021-10-07 19:39:19 +00:00
|
|
|
Skip: codegen.NewStringSet("nodejs/test"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: "output-funcs-tfbridge20",
|
|
|
|
Description: "Similar to output-funcs, but with compatibility: tfbridge20, to simulate pulumi-aws use case",
|
2021-12-02 01:53:18 +00:00
|
|
|
SkipCompileCheck: codegen.NewStringSet(python),
|
2021-09-20 17:11:44 +00:00
|
|
|
},
|
2021-09-28 14:33:14 +00:00
|
|
|
{
|
|
|
|
Directory: "cyclic-types",
|
|
|
|
Description: "Cyclic object types",
|
|
|
|
},
|
2021-10-04 21:26:49 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-node-8110",
|
|
|
|
Description: "Test the fix for pulumi/pulumi#8110 nodejs compilation error",
|
2021-11-30 19:09:36 +00:00
|
|
|
Skip: codegen.NewStringSet("go/test", "dotnet/test"),
|
2021-10-04 21:26:49 +00:00
|
|
|
},
|
2021-10-12 16:13:13 +00:00
|
|
|
{
|
|
|
|
Directory: "dashed-import-schema",
|
|
|
|
Description: "Ensure that we handle all valid go import paths",
|
2021-11-30 19:09:36 +00:00
|
|
|
Skip: codegen.NewStringSet("go/test", "dotnet/test"),
|
2021-10-12 16:13:13 +00:00
|
|
|
},
|
2021-10-27 00:18:48 +00:00
|
|
|
{
|
2022-07-29 15:07:27 +00:00
|
|
|
Directory: "plain-and-default",
|
|
|
|
Description: "Ensure that a resource with a plain default property works correctly",
|
2021-10-27 00:18:48 +00:00
|
|
|
},
|
2021-11-18 20:23:30 +00:00
|
|
|
{
|
2021-12-02 01:53:18 +00:00
|
|
|
Directory: "plain-object-defaults",
|
|
|
|
Description: "Ensure that object defaults are generated (repro #8132)",
|
2021-11-23 23:10:15 +00:00
|
|
|
},
|
|
|
|
{
|
2021-12-02 01:53:18 +00:00
|
|
|
Directory: "plain-object-disable-defaults",
|
|
|
|
Description: "Ensure that we can still compile safely when defaults are disabled",
|
2021-11-18 20:23:30 +00:00
|
|
|
},
|
2021-11-25 01:13:47 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-8403",
|
|
|
|
Description: "Regress pulumi/pulumi#8403",
|
2021-12-10 21:13:50 +00:00
|
|
|
SkipCompileCheck: codegen.NewStringSet(python),
|
2021-11-25 01:13:47 +00:00
|
|
|
},
|
2021-12-08 05:21:04 +00:00
|
|
|
{
|
|
|
|
Directory: "different-package-name-conflict",
|
|
|
|
Description: "different packages with the same resource",
|
2022-01-21 20:58:11 +00:00
|
|
|
Skip: allLanguages,
|
2021-12-08 05:21:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: "different-enum",
|
|
|
|
Description: "An enum in a different package namespace",
|
|
|
|
Skip: codegen.NewStringSet("dotnet/compile"),
|
|
|
|
},
|
2023-12-05 12:29:30 +00:00
|
|
|
{
|
|
|
|
Directory: "array-of-enum-map",
|
|
|
|
Description: "A schema with an array of maps where the values are enums. Issue pulumi/pulumi#14734",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
2021-12-10 23:35:24 +00:00
|
|
|
{
|
|
|
|
Directory: "azure-native-nested-types",
|
|
|
|
Description: "Condensed example of nested collection types from Azure Native",
|
2022-08-16 10:38:10 +00:00
|
|
|
Skip: codegen.NewStringSet("go/any"),
|
2021-12-10 23:35:24 +00:00
|
|
|
},
|
2022-01-10 20:03:20 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-go-8664",
|
|
|
|
Description: "Regress pulumi/pulumi#8664 affecting Go",
|
2022-01-21 20:58:11 +00:00
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
2022-08-31 20:35:26 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-go-10527",
|
|
|
|
Description: "Regress pulumi/pulumi#10527 affecting Go",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
2023-05-18 21:59:43 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-go-12971",
|
|
|
|
Description: "Regress pulumi/pulumi#12971 affecting Go",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
2024-03-14 14:21:15 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-go-15478",
|
|
|
|
Description: "Regress pulumi/pulumi#15478 affecting Go ensuring SDK-gen doesn't panic",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
// skipping the compile step because the generated code emits nested types that are not supported by the Go SDK
|
|
|
|
SkipCompileCheck: codegen.NewStringSet(golang),
|
|
|
|
},
|
2023-06-09 14:53:20 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-py-12546",
|
|
|
|
Description: "Regress pulumi/pulumi#12546 affecting Python",
|
|
|
|
Skip: allLanguages.Except("python/any"),
|
|
|
|
},
|
2023-03-17 18:30:55 +00:00
|
|
|
{
|
|
|
|
Directory: "docs-collision",
|
|
|
|
Description: "Tests that resources and functions with the same name do not clobber each other.",
|
|
|
|
Skip: allLanguages.Except("docs/any"),
|
|
|
|
},
|
2024-03-28 17:14:47 +00:00
|
|
|
{
|
|
|
|
Directory: "using-shared-types-in-config",
|
|
|
|
Description: "Tests that shared types can be used in config.",
|
|
|
|
},
|
2022-01-21 20:58:11 +00:00
|
|
|
{
|
|
|
|
Directory: "other-owned",
|
|
|
|
Description: "CSharp rootNamespaces",
|
|
|
|
// We only test in dotnet, because we are testing a change in a dotnet
|
|
|
|
// language property. Other tests should pass, but do not put the
|
|
|
|
// relevant feature under test. To save time, we skip them.
|
|
|
|
//
|
|
|
|
// We need to see dotnet changes (paths) in the docs too.
|
|
|
|
Skip: allLanguages.Except("dotnet/any").Except("docs/any"),
|
2022-01-10 20:03:20 +00:00
|
|
|
},
|
2022-01-28 21:28:55 +00:00
|
|
|
{
|
|
|
|
Directory: "external-node-compatibility",
|
|
|
|
// In this case, this test's schema has kubernetes20 set, but is referencing a type from Google Native
|
|
|
|
// which doesn't have any compatibility modes set, so the referenced type should be `AuditConfigArgs`
|
|
|
|
// (with the `Args` suffix) and not `AuditConfig`.
|
|
|
|
Description: "Ensure external package compatibility modes are used when referencing external types",
|
|
|
|
Skip: allLanguages.Except("nodejs/any"),
|
|
|
|
},
|
2022-02-03 15:43:05 +00:00
|
|
|
{
|
|
|
|
Directory: "external-go-import-aliases",
|
|
|
|
// Google Native has its own import aliases, so those should be respected, unless there are local aliases.
|
|
|
|
// AWS Classic doesn't have any import aliases, so none should be used, unless there are local aliases.
|
|
|
|
Description: "Ensure external import aliases are honored, and any local import aliases override them",
|
2024-01-17 09:09:53 +00:00
|
|
|
Skip: allLanguages.Except("go/any"),
|
2022-02-03 15:43:05 +00:00
|
|
|
},
|
2022-02-03 16:49:06 +00:00
|
|
|
{
|
|
|
|
Directory: "external-python-same-module-name",
|
|
|
|
Description: "Ensure referencing external types/resources with the same module name are referenced correctly",
|
|
|
|
Skip: allLanguages.Except("python/any"),
|
|
|
|
},
|
2022-05-12 08:59:56 +00:00
|
|
|
{
|
2022-07-06 18:35:31 +00:00
|
|
|
Directory: "enum-reference",
|
2022-05-12 08:59:56 +00:00
|
|
|
Description: "Ensure referencing external types/resources with referenced enums import correctly",
|
|
|
|
},
|
2023-07-27 17:00:02 +00:00
|
|
|
{
|
|
|
|
Directory: "enum-reference-python",
|
|
|
|
Description: "Ensure referencing external types/resources with referenced enums import correctly in Python",
|
|
|
|
Skip: allLanguages.Except("python/any"),
|
|
|
|
},
|
2022-07-29 15:07:27 +00:00
|
|
|
{
|
|
|
|
Directory: "external-enum",
|
|
|
|
Description: "Ensure we generate valid tokens for external enums",
|
|
|
|
Skip: codegen.NewStringSet("dotnet/any"),
|
|
|
|
},
|
2022-03-19 00:02:33 +00:00
|
|
|
{
|
|
|
|
Directory: "internal-dependencies-go",
|
|
|
|
Description: "Emit Go internal dependencies",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
2023-08-22 17:16:43 +00:00
|
|
|
{
|
|
|
|
Directory: "go-overridden-internal-module-name",
|
|
|
|
Description: "Go SDK where the internal module name is overridden to be 'utilities'",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
2022-04-21 09:29:30 +00:00
|
|
|
{
|
|
|
|
Directory: "go-plain-ref-repro",
|
|
|
|
Description: "Generate a resource that accepts a plain input type",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
2022-06-21 18:04:13 +00:00
|
|
|
{
|
|
|
|
Directory: "go-nested-collections",
|
|
|
|
Description: "Generate a resource that outputs [][][]Foo",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
2022-09-23 19:44:31 +00:00
|
|
|
{
|
|
|
|
Directory: "functions-secrets",
|
|
|
|
// Secret properties for non-Output<T> returning functions cannot be secret because they are plain.
|
|
|
|
Description: "functions that have properties that are secrets in the schema",
|
|
|
|
},
|
2022-09-26 16:57:05 +00:00
|
|
|
{
|
|
|
|
Directory: "secrets",
|
|
|
|
Description: "Generate a resource with secret properties",
|
|
|
|
SkipCompileCheck: codegen.NewStringSet(dotnet),
|
|
|
|
},
|
2022-10-05 19:19:29 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-py-tfbridge-611",
|
|
|
|
Description: "Regresses pulumi/pulumi-terraform-bridge#611",
|
|
|
|
Skip: allLanguages.Except("python/any").Union(codegen.NewStringSet("python/test", "python/py_compile")),
|
|
|
|
},
|
2022-10-17 16:37:07 +00:00
|
|
|
{
|
|
|
|
Directory: "hyphenated-symbols",
|
|
|
|
Description: "Test that types can have names with hyphens in them",
|
|
|
|
Skip: allLanguages.Except("go/any").Except("python/any"),
|
|
|
|
},
|
2023-01-24 13:43:26 +00:00
|
|
|
{
|
|
|
|
Directory: "provider-type-schema",
|
|
|
|
Description: "A schema with a type called Provider schema",
|
|
|
|
},
|
2023-04-13 09:34:17 +00:00
|
|
|
{
|
|
|
|
Directory: "embedded-crd-types",
|
|
|
|
Description: "A schema with CRD types with package names different from the main package",
|
|
|
|
Skip: codegen.NewStringSet("dotnet/any"),
|
|
|
|
},
|
2023-11-29 12:37:53 +00:00
|
|
|
{
|
|
|
|
Directory: "unions-inside-arrays",
|
|
|
|
Description: "A schema with a union type inside an array",
|
|
|
|
},
|
2023-11-19 13:47:45 +00:00
|
|
|
{
|
|
|
|
Directory: "assets-and-archives",
|
|
|
|
Description: "A schema with assets and archives",
|
|
|
|
},
|
[sdkgen/python] Fix error calling _configure when the value is None (#14014)
We recently fixed an issue where defaults weren't set for nested objects
when the nested objects are passed as dicts (#13825). Unfortunately,
this introduced a regression when the nested object is optional, but it
itself has required fields, and the nested object is not specified. In
that case, an unintended error is raised.
Consider a `Provider` resource with an optional `certmanager:
ProviderCertmanagerArgs` argument, which itself has two required
properties: `mtls_cert_pem` and `mtls_key_pem`.
When creating a new `Provider` without specifying a `certmanager`, we
get an error:
```
TypeError: ProviderCertmanagerArgs._configure() missing 2 required positional arguments: 'mtls_cert_pem' and 'mtls_key_pem'
```
The source of the problem is this check in the generated `Provider`'s
constructor:
```python
if not isinstance(certmanager, ProviderCertmanagerArgs):
certmanager = certmanager or {}
def _setter(key, value):
certmanager[key] = value
ProviderCertmanagerArgs._configure(_setter, **certmanager)
```
When `certmanager` is not specified, its value is `None`, which is also
not an instance of `ProviderCertmanagerArgs`. So the code inside the
`if` executes. `ProviderCertmanagerArgs._configure` is called on an
empty dict, and the error is raised because there are two required
positional arguments to `ProviderCertmanagerArgs._configure`.
The fix is to add an additional check to ensure the value is not `None`.
Fixes #14012
2023-09-22 18:28:25 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-py-14012",
|
|
|
|
Description: "Regresses https://github.com/pulumi/pulumi/issues/14012",
|
|
|
|
Skip: allLanguages.Except("python/any"),
|
|
|
|
},
|
2023-11-28 16:59:41 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-py-14539",
|
|
|
|
Description: "Regresses https://github.com/pulumi/pulumi/issues/14539",
|
|
|
|
Skip: allLanguages.Except("python/any"),
|
|
|
|
},
|
2023-11-16 18:41:57 +00:00
|
|
|
{
|
|
|
|
Directory: "output-funcs-go-generics-only",
|
|
|
|
Description: "Tests targeting the $fn_output code generation feature, only for Go generics == generics-only",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: "plain-and-default-go-generics-only",
|
|
|
|
Description: "resource with a plain default property works, only for Go generics == generics-only",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: "secrets-go-generics-only",
|
|
|
|
Description: "Generate a resource with secret properties, only for Go generics == generics-only",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: "simple-enum-schema-go-generics-only",
|
|
|
|
Description: "Simple schema with enum types, only for Go generics == generics-only",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Directory: "simple-plain-schema-go-generics-only",
|
|
|
|
Description: "Simple schema with plain properties, only for Go generics == generics-only",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
2023-11-21 16:43:51 +00:00
|
|
|
{
|
|
|
|
Directory: "assets-and-archives-go-generics-only",
|
|
|
|
Description: "Testing generating a schema with assets and archives for go using generics-only",
|
|
|
|
Skip: allLanguages.Except("go/any"),
|
|
|
|
},
|
2023-11-23 02:43:38 +00:00
|
|
|
{
|
|
|
|
Directory: "urn-id-properties",
|
|
|
|
Description: "Testing urn and id properties in valid locations",
|
|
|
|
},
|
2024-01-05 09:05:41 +00:00
|
|
|
{
|
|
|
|
Directory: "regress-py-12980",
|
|
|
|
Description: "Import resources across modules",
|
|
|
|
Skip: allLanguages.Except("python/any"),
|
|
|
|
},
|
2023-12-11 17:39:47 +00:00
|
|
|
{
|
|
|
|
Directory: "unions-inline",
|
|
|
|
Description: "Testing the use of unions/oneOf in the schema inline with the property definition.",
|
|
|
|
},
|
2024-02-15 13:44:44 +00:00
|
|
|
{
|
|
|
|
Directory: "legacy-names",
|
|
|
|
Description: "Testing the use of snake_case names and tokens.",
|
|
|
|
Skip: codegen.NewStringSet("go/test"),
|
|
|
|
},
|
[dotnet] codegen fix for resources without constant input properties (#15488)
<!---
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. -->
This PR fixes a bug in the dotnet codegen where the wrong "args" class
name would be used, in the case that the resource has no constant
inputs. This is an edge case because most resources do have at least one
such input.
For example, a new resource definition in p/k produced this output:
```csharp
namespace Pulumi.Kubernetes.Yaml.V2
{
public ConfigGroup(string name, Pulumi.Kubernetes.Types.Inputs.Yaml.V2.ConfigGroupArgs? args = null, CustomResourceOptions? options = null)
: base("kubernetes:yaml/v2:ConfigGroup", name, args ?? new ConfigGroupArgs(), MakeResourceOptions(options, ""), remote: true)
{
}
}
```
Which doesn't compile because `ConfigGroupArgs` is in a separate
namespace.
Should be:
```csharp
public ConfigGroup(string name, Pulumi.Kubernetes.Types.Inputs.Yaml.V2.ConfigGroupArgs? args = null, CustomResourceOptions? options = null)
: base("kubernetes:yaml/v2:ConfigGroup", name, args ?? new Pulumi.Kubernetes.Types.Inputs.Yaml.V2.ConfigGroupArgs(), MakeResourceOptions(options, ""), remote: true)
{
}
```
[Here's
](https://github.com/pulumi/pulumi/pull/15488/files#diff-18b12fabab20d68398aced2890b1ca3073cc32081bb62a022b77a5090c209e3bR45)where
the fix manifests itself in the new test case.
## Testing
A new SDK test case was added to cover the whole `kubernetes20`
compatibility mode, based on a simplified schema from the
pulumi-kubernetes provider.
The schema contains a representative set of resources:
1. `kubernetes:core/v1:ConfigMap` - a non-overlay resource representing
a Kubernetes kind.
2. `kubernetes:core/v1:ConfigMapList` - a Kubernetes list kind
3. `kubernetes:helm.sh/v3:Release` - a non-overlay, non-Kubernetes
resource
4. `kubernetes:yaml:ConfigGroup` - an overlay component resource
An important detail is whether a resource has any input properties that
have a constant value, such as we see with `kind` and `apiVersion`. The
`Release` resource intentionally has no such constant inputs.
## 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. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] 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. -->
2024-03-02 06:01:31 +00:00
|
|
|
{
|
|
|
|
Directory: "kubernetes20",
|
|
|
|
Description: "Testing the kubernetes20 compatibility mode.",
|
|
|
|
Skip: codegen.NewStringSet("go/test"),
|
|
|
|
},
|
2021-09-28 14:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var genSDKOnly bool
|
|
|
|
|
|
|
|
func NoSDKCodegenChecks() bool {
|
|
|
|
return genSDKOnly
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2021-12-10 23:35:24 +00:00
|
|
|
noChecks := false
|
|
|
|
if env, ok := os.LookupEnv("PULUMI_TEST_SDK_NO_CHECKS"); ok {
|
|
|
|
noChecks, _ = strconv.ParseBool(env)
|
|
|
|
}
|
|
|
|
flag.BoolVar(&genSDKOnly, "sdk.no-checks", noChecks, "when set, skips all post-SDK-generation checks")
|
|
|
|
|
2021-09-28 14:33:14 +00:00
|
|
|
// NOTE: the testing package will call flag.Parse.
|
2021-07-06 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 11:10:04 +00:00
|
|
|
// SDKCodegenOptions describes the set of codegen tests for a language.
|
2021-09-22 17:55:20 +00:00
|
|
|
type SDKCodegenOptions struct {
|
|
|
|
// Name of the programming language.
|
|
|
|
Language string
|
|
|
|
|
|
|
|
// Language-aware code generator; such as `GeneratePackage`.
|
2021-09-23 17:12:27 +00:00
|
|
|
// from `codegen/dotnet`.
|
2021-09-22 17:55:20 +00:00
|
|
|
GenPackage GenPkgSignature
|
|
|
|
|
|
|
|
// Extra checks for all the tests. They keys of this map are
|
|
|
|
// of the form "$language/$check" such as "go/compile".
|
|
|
|
Checks map[string]CodegenCheck
|
2022-02-07 11:10:04 +00:00
|
|
|
|
|
|
|
// The tests to run. A testcase `tt` are assumed to be located at
|
|
|
|
// ../testing/test/testdata/${tt.Directory}
|
2022-03-04 08:17:41 +00:00
|
|
|
TestCases []*SDKTest
|
2021-09-22 17:55:20 +00:00
|
|
|
}
|
2021-09-15 16:49:36 +00:00
|
|
|
|
2021-11-12 00:00:03 +00:00
|
|
|
// TestSDKCodegen runs the complete set of SDK code generation tests
|
2021-09-22 17:55:20 +00:00
|
|
|
// against a particular language's code generator. It also verifies
|
|
|
|
// that the generated code is structurally sound.
|
|
|
|
//
|
2022-02-07 11:10:04 +00:00
|
|
|
// The test files live in `pkg/codegen/testing/test/testdata` and
|
2021-09-22 17:55:20 +00:00
|
|
|
// are registered in `var sdkTests` in `sdk_driver.go`.
|
|
|
|
//
|
|
|
|
// An SDK code generation test files consists of a schema and a set of
|
|
|
|
// expected outputs for each language. Each test is structured as a
|
|
|
|
// directory that contains that information:
|
|
|
|
//
|
2022-09-14 02:12:02 +00:00
|
|
|
// testdata/
|
|
|
|
// my-simple-schema/ # i.e. `simple-enum-schema`
|
|
|
|
// schema.(json|yaml)
|
|
|
|
// go/
|
|
|
|
// python/
|
|
|
|
// nodejs/
|
|
|
|
// dotnet/
|
|
|
|
// ...
|
2021-09-22 17:55:20 +00:00
|
|
|
//
|
|
|
|
// The schema is the only piece that *must* be manually authored.
|
|
|
|
//
|
|
|
|
// Once the schema has been written, the actual codegen outputs can be
|
|
|
|
// generated by running the following in `pkg/codegen` directory:
|
2021-07-06 22:40:53 +00:00
|
|
|
//
|
2022-09-14 02:12:02 +00:00
|
|
|
// PULUMI_ACCEPT=true go test ./...
|
2021-07-06 22:40:53 +00:00
|
|
|
//
|
2021-09-22 17:55:20 +00:00
|
|
|
// This will rebuild subfolders such as `go/` from scratch and store
|
2021-11-12 00:00:03 +00:00
|
|
|
// the set of code-generated file names in `go/codegen-manifest.json`.
|
2021-09-22 17:55:20 +00:00
|
|
|
// If these outputs look correct, they need to be checked into git and
|
|
|
|
// will then serve as the expected values for the normal test runs:
|
2021-07-06 22:40:53 +00:00
|
|
|
//
|
2022-09-14 02:12:02 +00:00
|
|
|
// go test ./...
|
2021-09-22 17:55:20 +00:00
|
|
|
//
|
|
|
|
// That is, the normal test runs will fail if changes to codegen or
|
|
|
|
// schema lead to a diff in the generated file set. If the diff is
|
|
|
|
// intentional, it can be accepted again via `PULUMI_ACCEPT=true`.
|
|
|
|
//
|
|
|
|
// To support running unit tests over the generated code, the tests
|
|
|
|
// also support mixing in manually written `$lang-extras` files into
|
|
|
|
// the generated tree. For example, given the following input:
|
|
|
|
//
|
2022-09-14 02:12:02 +00:00
|
|
|
// testdata/
|
|
|
|
// my-simple-schema/
|
|
|
|
// schema.json
|
|
|
|
// go/
|
|
|
|
// go-extras/
|
|
|
|
// tests/
|
|
|
|
// go_test.go
|
2021-09-22 17:55:20 +00:00
|
|
|
//
|
|
|
|
// The system will copy `go-extras/tests/go_test.go` into
|
|
|
|
// `go/tests/go_test.go` before performing compilation and unit test
|
|
|
|
// checks over the project generated in `go`.
|
|
|
|
func TestSDKCodegen(t *testing.T, opts *SDKCodegenOptions) { // revive:disable-line
|
2022-01-08 03:27:14 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
t.Skip("TestSDKCodegen is skipped on Windows")
|
|
|
|
}
|
|
|
|
|
2022-02-07 11:10:04 +00:00
|
|
|
testDir := filepath.Join("..", "testing", "test", "testdata")
|
2021-07-06 22:40:53 +00:00
|
|
|
|
2022-02-07 11:10:04 +00:00
|
|
|
require.NotNil(t, opts.TestCases, "No test cases were provided. This was probably a mistake")
|
2022-03-04 08:17:41 +00:00
|
|
|
for _, tt := range opts.TestCases {
|
|
|
|
tt := tt // avoid capturing loop variable `sdkTest` in the closure
|
2022-06-14 06:27:11 +00:00
|
|
|
|
2021-09-23 17:42:20 +00:00
|
|
|
t.Run(tt.Directory, func(t *testing.T) {
|
2022-03-04 08:17:41 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
tt.Mutex.Lock()
|
|
|
|
t.Cleanup(tt.Mutex.Unlock)
|
2021-09-23 17:42:20 +00:00
|
|
|
|
|
|
|
t.Log(tt.Description)
|
|
|
|
|
2021-07-13 23:41:40 +00:00
|
|
|
dirPath := filepath.Join(testDir, filepath.FromSlash(tt.Directory))
|
|
|
|
|
|
|
|
schemaPath := filepath.Join(dirPath, "schema.json")
|
|
|
|
if _, err := os.Stat(schemaPath); err != nil && os.IsNotExist(err) {
|
|
|
|
schemaPath = filepath.Join(dirPath, "schema.yaml")
|
|
|
|
}
|
|
|
|
|
2022-01-21 20:58:11 +00:00
|
|
|
if tt.ShouldSkipCodegen(opts.Language) {
|
2021-12-08 05:21:04 +00:00
|
|
|
t.Logf("Skipping generation + tests for %s", tt.Directory)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-22 17:55:20 +00:00
|
|
|
files, err := GeneratePackageFilesFromSchema(schemaPath, opts.GenPackage)
|
2021-07-27 02:23:17 +00:00
|
|
|
require.NoError(t, err)
|
2021-07-06 22:40:53 +00:00
|
|
|
|
2021-09-22 17:55:20 +00:00
|
|
|
if !RewriteFilesWhenPulumiAccept(t, dirPath, opts.Language, files) {
|
|
|
|
expectedFiles, err := LoadBaseline(dirPath, opts.Language)
|
2021-07-27 02:23:17 +00:00
|
|
|
require.NoError(t, err)
|
2021-07-06 22:40:53 +00:00
|
|
|
|
2021-07-27 02:23:17 +00:00
|
|
|
if !ValidateFileEquality(t, files, expectedFiles) {
|
2021-09-22 17:55:20 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 14:33:14 +00:00
|
|
|
if genSDKOnly {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-22 17:55:20 +00:00
|
|
|
CopyExtraFiles(t, dirPath, opts.Language)
|
|
|
|
|
|
|
|
// Merge language-specific global and
|
|
|
|
// test-specific checks, with test-specific
|
|
|
|
// having precedence.
|
|
|
|
allChecks := make(map[string]CodegenCheck)
|
|
|
|
for k, v := range opts.Checks {
|
|
|
|
allChecks[k] = v
|
|
|
|
}
|
|
|
|
for k, v := range tt.Checks {
|
|
|
|
allChecks[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the checks in alphabetical order.
|
|
|
|
var checkOrder []string
|
|
|
|
for check := range allChecks {
|
|
|
|
checkOrder = append(checkOrder, check)
|
|
|
|
}
|
|
|
|
sort.Strings(checkOrder)
|
|
|
|
|
|
|
|
codeDir := filepath.Join(dirPath, opts.Language)
|
|
|
|
|
|
|
|
// Perform the checks.
|
2022-03-04 08:17:41 +00:00
|
|
|
//nolint:paralleltest // test functions are ordered
|
|
|
|
for _, check := range checkOrder {
|
|
|
|
check := check
|
2021-09-22 17:55:20 +00:00
|
|
|
t.Run(check, func(t *testing.T) {
|
2022-01-21 20:58:11 +00:00
|
|
|
if tt.ShouldSkipTest(opts.Language, check) {
|
2021-09-22 17:55:20 +00:00
|
|
|
t.Skip()
|
|
|
|
}
|
|
|
|
checkFun := allChecks[check]
|
|
|
|
checkFun(t, codeDir)
|
|
|
|
})
|
2021-07-27 02:23:17 +00:00
|
|
|
}
|
2021-07-06 22:40:53 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|