Skip to content
Draft
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
83 changes: 83 additions & 0 deletions pkg/tests/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions pkg/tests/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Build a Nix flake that defines a development environment.
# Use this flake as an input:
#
# https://github.com/nyobe/pulumi-flake/tree/v3.146.0



# Here's a Nix flake that defines a development environment using the pulumi-flake as an input:


{
description = "Development environment with Pulumi";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pulumi-flake = {
url = "github:nyobe/pulumi-flake/v3.139.0";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils, pulumi-flake }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
pulumi = pulumi-flake.packages.${system};
in
{
devShells.default = pkgs.mkShell {
buildInputs = [
pulumi.default
pkgs.go
pkgs.git
];
};
});
}
141 changes: 141 additions & 0 deletions pkg/tests/regress_vsphere_824_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package tests

import (
"bytes"
"context"
"encoding/json"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"

Check failure on line 11 in pkg/tests/regress_vsphere_824_test.go

View workflow job for this annotation

GitHub Actions / Test and Lint / lint

File is not properly formatted (gci)

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/pulcheck"
"github.com/pulumi/pulumi/sdk/v3/go/auto/debug"
"github.com/pulumi/pulumi/sdk/v3/go/auto/optup"
)

// The test is set up to reproduce https://github.com/pulumi/pulumi-vsphere/issues/824
func Test_RegressVSphere824(t *testing.T) {
t.Parallel()

subResourceSchema := map[string]*schema.Schema{
"label": {
Type: schema.TypeString,
Required: true,
},
"datastore_id": {
Type: schema.TypeString,
Optional: true,
},
}

res := &schema.Resource{
Schema: map[string]*schema.Schema{
"disk": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Description: "A specification for a virtual disk device on this virtual machine.",
MaxItems: 60,
Elem: &schema.Resource{Schema: subResourceSchema},
},
},
}

tfp := &schema.Provider{
ResourcesMap: map[string]*schema.Resource{"prov_test": res},
}

bridgedProvider := pulcheck.BridgedProvider(t, "prov", tfp)

program1 := `
name: test
runtime: yaml
resources:
mainRes:
type: prov:index:Test
properties:
disks:
- label: label1
datastoreId: ds1
- label: label2
datastoreId: ds2
options:
ignoreChanges:
- "disks[*].datastoreId"
`
pt := pulcheck.PulCheck(t, bridgedProvider, program1)

out := pt.Up(t)
t.Logf("# update 1: %v", out.StdErr+out.StdOut)

d := pt.ExportStack(t)
text, err := json.MarshalIndent(d, "", " ")
require.NoError(t, err)
t.Logf("STATE: %s", text)

program2 := `
name: test
runtime: yaml
resources:
mainRes:
type: prov:index:Test
properties:
disks:
- label: label1
datastoreId: ds1
- label: label2
datastoreId: ds2
- label: label3
datastoreId: ds3
options:
ignoreChanges:
- "disks[*].datastoreId"
`

pp := func(j json.RawMessage) string {
var buf bytes.Buffer
err := json.Indent(&buf, j, "", " ")
if err != nil {
return string(j)
}
return buf.String()
}

for _, e := range pt.GrpcLog(t).Entries {
t.Logf("%q:\n%s\n=> %s", e.Method, pp(e.Request), pp(e.Response))
}

err = os.WriteFile(filepath.Join(pt.WorkingDir(), "Pulumi.yaml"), []byte(program2), 0655)

Check failure on line 111 in pkg/tests/regress_vsphere_824_test.go

View workflow job for this annotation

GitHub Actions / Test and Lint / lint

G306: Expect WriteFile permissions to be 0600 or less (gosec)
require.NoError(t, err)

pt.ClearGrpcLog(t)

var debugOpts debug.LoggingOptions

// To enable debug logging in this test, un-comment:
// logLevel := uint(13)
// debugOpts = debug.LoggingOptions{
// LogLevel: &logLevel,
// LogToStdErr: true,
// FlowToPlugins: true,
// Debug: true,
// }

out2, err := pt.CurrentStack().Up(context.Background(),
optup.DebugLogging(debugOpts),
)

t.Logf("GRPC entries: %d", len(pt.GrpcLog(t).Entries))

for _, e := range pt.GrpcLog(t).Entries {
t.Logf("%q:\n%s\n=> %s", e.Method, pp(e.Request), pp(e.Response))
}

t.Logf("# update 2: %v", out2.StdErr+out2.StdOut)

t.Logf("PULUMI VERSION %v", pt.CurrentStack().Workspace().PulumiCommand().Version())
require.NoError(t, err)
}
Loading