-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Presently, the majority of Java code generation is driven by the `pulumi-java-gen` binary, since Java usage began before we had time to implement the `Generate*` family of language host gRPC methods. Recently, these gRPC methods were implemented, to support (among other things) conformance testing. Unfortunately, while both routes end in `pkg/codegen/java`'s `Generate*` functions, each had accumulated its own special "setup logic" ahead of the call into `pkg/codegen`. This commit attempts to sort this out, pushing all that logic into `pkg/codegen` so that both routes behave identically. As a result of this, we should be able to deprecate `pulumi-java-gen` more safely when the time comes, remove direct build-time dependencies on `pulumi-java` from `pulumi/pulumi` and fix some issues that have arisen as a result of the historic differences, such as #1404 (which looks like it may have already been fixed, but this should cement it) and #1508. Closes #1404 Fixes #1508
- Loading branch information
Showing
6 changed files
with
242 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// Copyright 2024, Pulumi Corporation. All rights reserved. | ||
|
||
package java | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/hcl/v2" | ||
"github.com/pulumi/pulumi/pkg/v3/codegen/schema" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDeduplicateTypes(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
input *schema.PackageSpec | ||
expectedSpec *schema.PackageSpec | ||
expectedDiags hcl.Diagnostics | ||
}{ | ||
{ | ||
name: "no duplicates", | ||
input: &schema.PackageSpec{}, | ||
expectedSpec: &schema.PackageSpec{}, | ||
expectedDiags: hcl.Diagnostics{}, | ||
}, | ||
{ | ||
name: "duplicates, lowercase", | ||
input: &schema.PackageSpec{ | ||
Types: map[string]schema.ComplexTypeSpec{ | ||
"azure-native:network:ipallocationmethod": {}, | ||
"azure-native:network:IpAllocationMethod": {}, | ||
}, | ||
}, | ||
expectedSpec: &schema.PackageSpec{ | ||
Types: map[string]schema.ComplexTypeSpec{ | ||
"azure-native:network:IpAllocationMethod": {}, | ||
}, | ||
}, | ||
expectedDiags: hcl.Diagnostics{ | ||
&hcl.Diagnostic{ | ||
Severity: hcl.DiagWarning, | ||
Summary: "Renaming 'azure-native:network:ipallocationmethod' to " + | ||
"'azure-native:network:IpAllocationMethod' in the schema", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "duplicates, uppercase", | ||
input: &schema.PackageSpec{ | ||
Types: map[string]schema.ComplexTypeSpec{ | ||
"azure-native:network:IPAllocationMethod": {}, | ||
"azure-native:network:IpAllocationMethod": {}, | ||
}, | ||
}, | ||
expectedSpec: &schema.PackageSpec{ | ||
Types: map[string]schema.ComplexTypeSpec{ | ||
"azure-native:network:IPAllocationMethod": {}, | ||
}, | ||
}, | ||
expectedDiags: hcl.Diagnostics{ | ||
&hcl.Diagnostic{ | ||
Severity: hcl.DiagWarning, | ||
Summary: "Renaming 'azure-native:network:IpAllocationMethod' to " + | ||
"'azure-native:network:IPAllocationMethod' in the schema", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "multiple duplicates", | ||
input: &schema.PackageSpec{ | ||
Types: map[string]schema.ComplexTypeSpec{ | ||
"azure-native:network:ipallocationmethod": {}, | ||
"azure-native:network:IPAllocationMethod": {}, | ||
"azure-native:network:IpAllocationMethod": {}, | ||
}, | ||
}, | ||
expectedSpec: &schema.PackageSpec{ | ||
Types: map[string]schema.ComplexTypeSpec{ | ||
"azure-native:network:IPAllocationMethod": {}, | ||
}, | ||
}, | ||
expectedDiags: hcl.Diagnostics{ | ||
&hcl.Diagnostic{ | ||
Severity: hcl.DiagWarning, | ||
Summary: "Renaming 'azure-native:network:ipallocationmethod' to " + | ||
"'azure-native:network:IPAllocationMethod' in the schema", | ||
}, | ||
&hcl.Diagnostic{ | ||
Severity: hcl.DiagWarning, | ||
Summary: "Renaming 'azure-native:network:IpAllocationMethod' to " + | ||
"'azure-native:network:IPAllocationMethod' in the schema", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "multiple duplicates and non-duplicates", | ||
input: &schema.PackageSpec{ | ||
Types: map[string]schema.ComplexTypeSpec{ | ||
"azure-native:network:other": {}, | ||
"azure-native:network:ipsallocationmethod": {}, | ||
"azure-native:network:ip_allocationmethod": {}, | ||
"azure-native:network:ipallocationmethod": {}, | ||
"azure-native:network:IPAllocationMethod": {}, | ||
"azure-native:network:IpAllocationMethod": {}, | ||
}, | ||
}, | ||
expectedSpec: &schema.PackageSpec{ | ||
Types: map[string]schema.ComplexTypeSpec{ | ||
"azure-native:network:other": {}, | ||
"azure-native:network:ipsallocationmethod": {}, | ||
"azure-native:network:ip_allocationmethod": {}, | ||
"azure-native:network:IPAllocationMethod": {}, | ||
}, | ||
}, | ||
expectedDiags: hcl.Diagnostics{ | ||
&hcl.Diagnostic{ | ||
Severity: hcl.DiagWarning, | ||
Summary: "Renaming 'azure-native:network:ipallocationmethod' to " + | ||
"'azure-native:network:IPAllocationMethod' in the schema", | ||
}, | ||
&hcl.Diagnostic{ | ||
Severity: hcl.DiagWarning, | ||
Summary: "Renaming 'azure-native:network:IpAllocationMethod' to " + | ||
"'azure-native:network:IPAllocationMethod' in the schema", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
actualSpec, actualDiags, err := DeduplicateTypes(c.input) | ||
require.NoError(t, err) | ||
require.ElementsMatch(t, c.expectedDiags, actualDiags) | ||
require.Equal(t, c.expectedSpec, actualSpec) | ||
}) | ||
} | ||
} |
Oops, something went wrong.