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

Fix NodeJS metadata type #159

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# CHANGELOG

## Unreleased
## 1.5.4 (2024-11-13)

- NodeJS now uses correct input/output types for object metadata. (https://github.com/pulumi/crd2pulumi/issues/158)

## 1.5.3 (2024-09-30)

Expand Down
2 changes: 1 addition & 1 deletion pkg/codegen/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type ObjectMetaPatch = k8s.types.input.meta.v1.ObjectMetaPatch;
`

func GenerateNodeJS(pg *PackageGenerator, name string) (map[string]*bytes.Buffer, error) {
pkg := pg.SchemaPackage()
pkg := pg.SchemaPackageWithObjectMetaType()
oldName := pkg.Name
pkg.Name = name

Expand Down
23 changes: 23 additions & 0 deletions tests/crds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,29 @@ func TestKubernetesVersionNodeJs(t *testing.T) {
execCrd2Pulumi(t, "nodejs", "crds/k8sversion/mock_crd.yaml", validateVersion)
}

func TestNodeJsObjectMeta(t *testing.T) {
validateVersion := func(t *testing.T, path string) {
// enter and build the generated package
withDir(t, path, func() {
runRequireNoError(t, exec.Command("npm", "install"))
runRequireNoError(t, exec.Command("npm", "run", "build"))

filename := filepath.Join(path, "k8sversion", "test", "testResource.ts")
t.Logf("validating objectmeta type in %s", filename)

testResource, err := os.ReadFile(filename)
if err != nil {
t.Fatalf("expected to read generated NodeJS code: %s", err)
}

assert.Contains(t, string(testResource), "public readonly metadata!: pulumi.Output<outputs.meta.v1.ObjectMeta>;", "expected metadata output type")
assert.Contains(t, string(testResource), "metadata?: pulumi.Input<inputs.meta.v1.ObjectMeta>;", "expected metadata input type")
Comment on lines +277 to +278
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were previously pulumi.Output<ObjectMeta> and pulumi.Input<ObjectMeta> respectively.

})
}

execCrd2Pulumi(t, "nodejs", "crds/k8sversion/mock_crd.yaml", validateVersion)
}

func withDir(t *testing.T, dir string, f func()) {
pwd, err := os.Getwd()
require.NoError(t, err)
Expand Down
Loading