Update nodejs gen-tests (#5477)
This commit is contained in:
parent
5e3c14c8be
commit
59b906eb76
31
pkg/codegen/internal/test/testdata/simple-resource-schema/argFunction.ts
vendored
Normal file
31
pkg/codegen/internal/test/testdata/simple-resource-schema/argFunction.ts
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
// *** WARNING: this file was generated by test. ***
|
||||
// *** Do not edit by hand unless you're certain you know what you are doing! ***
|
||||
|
||||
import * as pulumi from "@pulumi/pulumi";
|
||||
import * as inputs from "./types/input";
|
||||
import * as outputs from "./types/output";
|
||||
import * as utilities from "./utilities";
|
||||
|
||||
import {Resource} from "./index";
|
||||
|
||||
export function argFunction(args?: ArgFunctionArgs, opts?: pulumi.InvokeOptions): Promise<ArgFunctionResult> {
|
||||
args = args || {};
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
|
||||
if (!opts.version) {
|
||||
opts.version = utilities.getVersion();
|
||||
}
|
||||
return pulumi.runtime.invoke("example::argFunction", {
|
||||
"arg1": args.arg1,
|
||||
}, opts);
|
||||
}
|
||||
|
||||
export interface ArgFunctionArgs {
|
||||
readonly arg1?: Resource;
|
||||
}
|
||||
|
||||
export interface ArgFunctionResult {
|
||||
readonly result?: Resource;
|
||||
}
|
56
pkg/codegen/internal/test/testdata/simple-resource-schema/otherResource.ts
vendored
Normal file
56
pkg/codegen/internal/test/testdata/simple-resource-schema/otherResource.ts
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
// *** WARNING: this file was generated by test. ***
|
||||
// *** Do not edit by hand unless you're certain you know what you are doing! ***
|
||||
|
||||
import * as pulumi from "@pulumi/pulumi";
|
||||
import * as utilities from "./utilities";
|
||||
|
||||
import {Resource} from "./index";
|
||||
|
||||
export class OtherResource extends pulumi.ComponentResource {
|
||||
/** @internal */
|
||||
public static readonly __pulumiType = 'example::OtherResource';
|
||||
|
||||
/**
|
||||
* Returns true if the given object is an instance of OtherResource. This is designed to work even
|
||||
* when multiple copies of the Pulumi SDK have been loaded into the same process.
|
||||
*/
|
||||
public static isInstance(obj: any): obj is OtherResource {
|
||||
if (obj === undefined || obj === null) {
|
||||
return false;
|
||||
}
|
||||
return obj['__pulumiType'] === OtherResource.__pulumiType;
|
||||
}
|
||||
|
||||
public readonly foo!: pulumi.Output<Resource | undefined>;
|
||||
|
||||
/**
|
||||
* Create a OtherResource resource with the given unique name, arguments, and options.
|
||||
*
|
||||
* @param name The _unique_ name of the resource.
|
||||
* @param args The arguments to use to populate this resource's properties.
|
||||
* @param opts A bag of options that control this resource's behavior.
|
||||
*/
|
||||
constructor(name: string, args?: OtherResourceArgs, opts?: pulumi.ComponentResourceOptions) {
|
||||
let inputs: pulumi.Inputs = {};
|
||||
if (!(opts && opts.id)) {
|
||||
inputs["foo"] = args ? args.foo : undefined;
|
||||
} else {
|
||||
inputs["foo"] = undefined /*out*/;
|
||||
}
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
|
||||
if (!opts.version) {
|
||||
opts.version = utilities.getVersion();
|
||||
}
|
||||
super(OtherResource.__pulumiType, name, inputs, opts, true /*remote*/);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The set of arguments for constructing a OtherResource resource.
|
||||
*/
|
||||
export interface OtherResourceArgs {
|
||||
readonly foo?: pulumi.Input<Resource>;
|
||||
}
|
66
pkg/codegen/internal/test/testdata/simple-resource-schema/resource.ts
vendored
Normal file
66
pkg/codegen/internal/test/testdata/simple-resource-schema/resource.ts
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
// *** WARNING: this file was generated by test. ***
|
||||
// *** Do not edit by hand unless you're certain you know what you are doing! ***
|
||||
|
||||
import * as pulumi from "@pulumi/pulumi";
|
||||
import * as utilities from "./utilities";
|
||||
|
||||
export class Resource extends pulumi.CustomResource {
|
||||
/**
|
||||
* Get an existing Resource resource's state with the given name, ID, and optional extra
|
||||
* properties used to qualify the lookup.
|
||||
*
|
||||
* @param name The _unique_ name of the resulting resource.
|
||||
* @param id The _unique_ provider ID of the resource to lookup.
|
||||
* @param opts Optional settings to control the behavior of the CustomResource.
|
||||
*/
|
||||
public static get(name: string, id: pulumi.Input<pulumi.ID>, opts?: pulumi.CustomResourceOptions): Resource {
|
||||
return new Resource(name, undefined as any, { ...opts, id: id });
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public static readonly __pulumiType = 'example::Resource';
|
||||
|
||||
/**
|
||||
* Returns true if the given object is an instance of Resource. This is designed to work even
|
||||
* when multiple copies of the Pulumi SDK have been loaded into the same process.
|
||||
*/
|
||||
public static isInstance(obj: any): obj is Resource {
|
||||
if (obj === undefined || obj === null) {
|
||||
return false;
|
||||
}
|
||||
return obj['__pulumiType'] === Resource.__pulumiType;
|
||||
}
|
||||
|
||||
public readonly bar!: pulumi.Output<string | undefined>;
|
||||
|
||||
/**
|
||||
* Create a Resource resource with the given unique name, arguments, and options.
|
||||
*
|
||||
* @param name The _unique_ name of the resource.
|
||||
* @param args The arguments to use to populate this resource's properties.
|
||||
* @param opts A bag of options that control this resource's behavior.
|
||||
*/
|
||||
constructor(name: string, args?: ResourceArgs, opts?: pulumi.CustomResourceOptions) {
|
||||
let inputs: pulumi.Inputs = {};
|
||||
if (!(opts && opts.id)) {
|
||||
inputs["bar"] = args ? args.bar : undefined;
|
||||
} else {
|
||||
inputs["bar"] = undefined /*out*/;
|
||||
}
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
|
||||
if (!opts.version) {
|
||||
opts.version = utilities.getVersion();
|
||||
}
|
||||
super(Resource.__pulumiType, name, inputs, opts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The set of arguments for constructing a Resource resource.
|
||||
*/
|
||||
export interface ResourceArgs {
|
||||
readonly bar?: pulumi.Input<string>;
|
||||
}
|
|
@ -12,61 +12,45 @@ import (
|
|||
|
||||
func TestGeneratePackage(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
schemaFile string
|
||||
wantErr bool
|
||||
validator func(files map[string][]byte)
|
||||
name string
|
||||
schemaDir string
|
||||
expectedFiles []string
|
||||
wantErr bool
|
||||
validator func(files, expectedFiles map[string][]byte)
|
||||
}{
|
||||
{
|
||||
"Simple schema with local resource properties",
|
||||
"simple-resource-schema.json",
|
||||
"simple-resource-schema",
|
||||
[]string{
|
||||
"resource.ts",
|
||||
"otherResource.ts",
|
||||
"argFunction.ts",
|
||||
},
|
||||
false,
|
||||
func(files map[string][]byte) {
|
||||
assert.Contains(t, files, "resource.ts")
|
||||
assert.Contains(t, files, "otherResource.ts")
|
||||
|
||||
for fileName, file := range files {
|
||||
if fileName == "resource.ts" {
|
||||
// Correct parent class
|
||||
assert.Contains(t, string(file), "export class Resource extends pulumi.CustomResource {")
|
||||
// Remote option not set
|
||||
assert.NotContains(t, string(file), ", true /*remote*/);")
|
||||
// CustomResource class contains a get method
|
||||
assert.Contains(t, string(file), "public static get(name: string")
|
||||
}
|
||||
if fileName == "otherResource.ts" {
|
||||
// Correct parent class
|
||||
assert.Contains(t, string(file), "export class OtherResource extends pulumi.ComponentResource {")
|
||||
// Remote resource option is set
|
||||
assert.Contains(t, string(file), "super(OtherResource.__pulumiType, name, inputs, opts, true /*remote*/);")
|
||||
// Correct import for local resource
|
||||
assert.Contains(t, string(file), `import {Resource} from "./index";`)
|
||||
// Correct type for resource input property
|
||||
assert.Contains(t, string(file), "readonly foo?: pulumi.Input<Resource>;")
|
||||
// Correct type for resource property
|
||||
assert.Contains(t, string(file), "public readonly foo!: pulumi.Output<Resource | undefined>;")
|
||||
// ComponentResource class does not contain a get method
|
||||
assert.NotContains(t, string(file), "public static get(name: string")
|
||||
}
|
||||
if fileName == "argFunction.ts" {
|
||||
// Correct import for local resource
|
||||
assert.Contains(t, string(file), `import {Resource} from "./index";`)
|
||||
// Correct type for function arg
|
||||
assert.Contains(t, string(file), "readonly arg1?: Resource;")
|
||||
// Correct type for result
|
||||
assert.Contains(t, string(file), "readonly result?: Resource;")
|
||||
}
|
||||
func(files, expectedFiles map[string][]byte) {
|
||||
for name, file := range expectedFiles {
|
||||
assert.Contains(t, files, name)
|
||||
assert.Equal(t, file, files[name])
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
testDir := filepath.Join("..", "internal", "test", "testdata")
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Read in, decode, and import the schema.
|
||||
schemaBytes, err := ioutil.ReadFile(
|
||||
filepath.Join("..", "internal", "test", "testdata", tt.schemaFile))
|
||||
filepath.Join(testDir, tt.schemaDir, "schema.json"))
|
||||
assert.NoError(t, err)
|
||||
|
||||
expectedFiles := map[string][]byte{}
|
||||
for _, file := range tt.expectedFiles {
|
||||
fileBytes, err := ioutil.ReadFile(filepath.Join(testDir, tt.schemaDir, file))
|
||||
assert.NoError(t, err)
|
||||
|
||||
expectedFiles[file] = fileBytes
|
||||
}
|
||||
|
||||
var pkgSpec schema.PackageSpec
|
||||
err = json.Unmarshal(schemaBytes, &pkgSpec)
|
||||
assert.NoError(t, err)
|
||||
|
@ -81,7 +65,7 @@ func TestGeneratePackage(t *testing.T) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
tt.validator(files)
|
||||
tt.validator(files, expectedFiles)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func TestGeneratePackage(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
"Simple schema with local resource properties",
|
||||
"simple-resource-schema.json",
|
||||
"simple-resource-schema/schema.json",
|
||||
false,
|
||||
func(files map[string][]byte) {
|
||||
assert.Contains(t, files, filepath.Join("pulumi_example", "resource.py"))
|
||||
|
|
|
@ -129,7 +129,7 @@ func TestImportResourceRef(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
"valid",
|
||||
"simple-resource-schema.json",
|
||||
"simple-resource-schema/schema.json",
|
||||
false,
|
||||
func(pkg *Package) {
|
||||
for _, r := range pkg.Resources {
|
||||
|
|
Loading…
Reference in a new issue