Skip to content

Commit b75030f

Browse files
Docs & variable tidy up (#131)
Stacked on #130
1 parent 638bf08 commit b75030f

File tree

18 files changed

+140
-139
lines changed

18 files changed

+140
-139
lines changed

go.mod

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ go 1.23
44

55
require (
66
github.com/gkampitakis/go-snaps v0.4.9
7-
github.com/pulumi/pulumi/pkg/v3 v3.143.0
8-
github.com/pulumi/pulumi/sdk/v3 v3.143.0
9-
github.com/stretchr/testify v1.9.0
7+
github.com/pulumi/pulumi/pkg/v3 v3.157.0
8+
github.com/pulumi/pulumi/sdk/v3 v3.157.0
9+
github.com/stretchr/testify v1.10.0
1010
google.golang.org/grpc v1.67.1
1111
google.golang.org/protobuf v1.35.1
1212
)
@@ -28,7 +28,7 @@ require (
2828
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
2929
github.com/BurntSushi/toml v1.2.1 // indirect
3030
github.com/Microsoft/go-winio v0.6.1 // indirect
31-
github.com/ProtonMail/go-crypto v1.0.0 // indirect
31+
github.com/ProtonMail/go-crypto v1.1.3 // indirect
3232
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
3333
github.com/agext/levenshtein v1.2.3 // indirect
3434
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
@@ -58,7 +58,7 @@ require (
5858
github.com/cheggaaa/pb v1.0.29 // indirect
5959
github.com/cloudflare/circl v1.3.7 // indirect
6060
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
61-
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
61+
github.com/cyphar/filepath-securejoin v0.3.6 // indirect
6262
github.com/davecgh/go-spew v1.1.1 // indirect
6363
github.com/deckarep/golang-set/v2 v2.5.0 // indirect
6464
github.com/djherbis/times v1.5.0 // indirect
@@ -69,15 +69,15 @@ require (
6969
github.com/gkampitakis/ciinfo v0.3.0 // indirect
7070
github.com/gkampitakis/go-diff v1.3.2 // indirect
7171
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
72-
github.com/go-git/go-billy/v5 v5.5.0 // indirect
73-
github.com/go-git/go-git/v5 v5.12.0 // indirect
74-
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
72+
github.com/go-git/go-billy/v5 v5.6.1 // indirect
73+
github.com/go-git/go-git/v5 v5.13.1 // indirect
74+
github.com/go-jose/go-jose/v3 v3.0.4 // indirect
7575
github.com/go-logr/logr v1.4.1 // indirect
7676
github.com/go-logr/stdr v1.2.2 // indirect
7777
github.com/gofrs/uuid v4.2.0+incompatible // indirect
7878
github.com/gogo/protobuf v1.3.2 // indirect
7979
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
80-
github.com/golang/glog v1.2.2 // indirect
80+
github.com/golang/glog v1.2.4 // indirect
8181
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
8282
github.com/golang/protobuf v1.5.4 // indirect
8383
github.com/google/go-querystring v1.1.0 // indirect
@@ -100,6 +100,7 @@ require (
100100
github.com/hashicorp/hcl/v2 v2.22.0 // indirect
101101
github.com/hashicorp/vault/api v1.12.0 // indirect
102102
github.com/inconshreveable/mousetrap v1.1.0 // indirect
103+
github.com/iwdgo/sigintwindows v0.2.2 // indirect
103104
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
104105
github.com/jmespath/go-jmespath v0.4.0 // indirect
105106
github.com/json-iterator/go v1.1.12 // indirect
@@ -144,7 +145,7 @@ require (
144145
github.com/segmentio/asm v1.1.3 // indirect
145146
github.com/segmentio/encoding v0.3.5 // indirect
146147
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
147-
github.com/skeema/knownhosts v1.2.2 // indirect
148+
github.com/skeema/knownhosts v1.3.0 // indirect
148149
github.com/spf13/cobra v1.8.0 // indirect
149150
github.com/spf13/pflag v1.0.5 // indirect
150151
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
@@ -168,17 +169,17 @@ require (
168169
go.uber.org/atomic v1.9.0 // indirect
169170
gocloud.dev v0.37.0 // indirect
170171
gocloud.dev/secrets/hashivault v0.37.0 // indirect
171-
golang.org/x/crypto v0.31.0 // indirect
172-
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect
173-
golang.org/x/mod v0.18.0 // indirect
174-
golang.org/x/net v0.33.0 // indirect
172+
golang.org/x/crypto v0.33.0 // indirect
173+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
174+
golang.org/x/mod v0.19.0 // indirect
175+
golang.org/x/net v0.35.0 // indirect
175176
golang.org/x/oauth2 v0.22.0 // indirect
176-
golang.org/x/sync v0.10.0 // indirect
177-
golang.org/x/sys v0.28.0 // indirect
178-
golang.org/x/term v0.27.0 // indirect
179-
golang.org/x/text v0.21.0 // indirect
177+
golang.org/x/sync v0.11.0 // indirect
178+
golang.org/x/sys v0.30.0 // indirect
179+
golang.org/x/term v0.29.0 // indirect
180+
golang.org/x/text v0.22.0 // indirect
180181
golang.org/x/time v0.5.0 // indirect
181-
golang.org/x/tools v0.22.0 // indirect
182+
golang.org/x/tools v0.23.0 // indirect
182183
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
183184
google.golang.org/api v0.169.0 // indirect
184185
google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect

go.sum

Lines changed: 46 additions & 56 deletions
Large diffs are not rendered by default.

optproviderupgrade/optproviderupgrade.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func CacheDir(elem ...string) PreviewProviderUpgradeOpt {
4040

4141
// NewSourcePath sets the path to new source code to use for the target version of the upgrade.
4242
// If not set, the original pulumitest program source is used.
43+
// Like the source argument to NewPulumiTest, the path can be absolute, or relative to the directory the test source is in.
4344
// This is useful for where it's expected for a user to perform code changes during a migration.
4445
func NewSourcePath(path string) PreviewProviderUpgradeOpt {
4546
return optionFunc(func(o *PreviewProviderUpgradeOptions) {

pulumitest/convert.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ func Convert(t PT, source, language string, opts ...opttest.Option) ConvertResul
3333

3434
// Convert a program to a given language.
3535
// It returns a new PulumiTest instance for the converted program which will be outputted into a temporary directory.
36-
func (a *PulumiTest) Convert(t PT, language string, opts ...opttest.Option) ConvertResult {
36+
func (pt *PulumiTest) Convert(t PT, language string, opts ...opttest.Option) ConvertResult {
3737
t.Helper()
3838

39-
options := a.options.Copy()
39+
options := pt.options.Copy()
4040
for _, opt := range opts {
4141
opt.Apply(options)
4242
}
4343

4444
tempDir := tempDirWithoutCleanupOnFailedTest(t, "converted", options.TempDir)
45-
base := filepath.Base(a.workingDir)
45+
base := filepath.Base(pt.workingDir)
4646
targetDir := filepath.Join(tempDir, fmt.Sprintf("%s-%s", base, language))
4747
err := os.Mkdir(targetDir, 0755)
4848
if err != nil {
@@ -51,14 +51,14 @@ func (a *PulumiTest) Convert(t PT, language string, opts ...opttest.Option) Conv
5151

5252
ptLogF(t, "converting to %s", language)
5353
cmd := exec.Command("pulumi", "convert", "--language", language, "--generate-only", "--out", targetDir)
54-
cmd.Dir = a.workingDir
54+
cmd.Dir = pt.workingDir
5555
out, err := cmd.CombinedOutput()
5656
if err != nil {
5757
ptFatalF(t, "failed to convert directory: %s\n%s", err, out)
5858
}
5959

6060
convertedTest := &PulumiTest{
61-
ctx: a.ctx,
61+
ctx: pt.ctx,
6262
workingDir: targetDir,
6363
options: options,
6464
}

pulumitest/copy.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,41 @@ import (
1212
// CopyToTempDir copies the program to a temporary directory.
1313
// It returns a new PulumiTest instance for the copied program.
1414
// This is used to avoid temporary files being written to the source directory.
15-
func (a *PulumiTest) CopyToTempDir(t PT, opts ...opttest.Option) *PulumiTest {
15+
func (pt *PulumiTest) CopyToTempDir(t PT, opts ...opttest.Option) *PulumiTest {
1616
t.Helper()
17-
options := a.options.Copy()
17+
options := pt.options.Copy()
1818
for _, opt := range opts {
1919
opt.Apply(options)
2020
}
2121
tempDir := tempDirWithoutCleanupOnFailedTest(t, "programDir", options.TempDir)
2222

2323
// Maintain the directory name in the temp dir as this might be used for stack naming.
24-
sourceBase := filepath.Base(a.workingDir)
24+
sourceBase := filepath.Base(pt.workingDir)
2525
destination := filepath.Join(tempDir, sourceBase)
2626
err := os.Mkdir(destination, 0755)
2727
if err != nil {
2828
ptFatal(t, err)
2929
}
3030

31-
return a.CopyTo(t, destination, opts...)
31+
return pt.CopyTo(t, destination, opts...)
3232
}
3333

3434
// CopyTo copies the program to the specified directory.
3535
// It returns a new PulumiTest instance for the copied program.
36-
func (a *PulumiTest) CopyTo(t PT, dir string, opts ...opttest.Option) *PulumiTest {
36+
func (pt *PulumiTest) CopyTo(t PT, dir string, opts ...opttest.Option) *PulumiTest {
3737
t.Helper()
3838

39-
err := copyDirectory(a.workingDir, dir)
39+
err := copyDirectory(pt.workingDir, dir)
4040
if err != nil {
4141
ptFatal(t, err)
4242
}
4343

44-
options := a.options.Copy()
44+
options := pt.options.Copy()
4545
for _, opt := range opts {
4646
opt.Apply(options)
4747
}
4848
newTest := &PulumiTest{
49-
ctx: a.ctx,
49+
ctx: pt.ctx,
5050
workingDir: dir,
5151
options: options,
5252
}

pulumitest/destroy.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ import (
55
"github.com/pulumi/pulumi/sdk/v3/go/auto/optdestroy"
66
)
77

8-
// Up deploys the current stack.
9-
func (a *PulumiTest) Destroy(t PT, opts ...optdestroy.Option) auto.DestroyResult {
8+
// Destroy the current stack.
9+
// If an error is expected, use `CurrentStack().Destroy()` instead to be returned the error.
10+
func (pt *PulumiTest) Destroy(t PT, opts ...optdestroy.Option) auto.DestroyResult {
1011
t.Helper()
1112

1213
t.Log("destroying")
13-
if a.currentStack == nil {
14+
if pt.currentStack == nil {
1415
ptFatal(t, "no current stack")
1516
}
16-
if !a.options.DisableGrpcLog {
17-
a.ClearGrpcLog(t)
17+
if !pt.options.DisableGrpcLog {
18+
pt.ClearGrpcLog(t)
1819
}
19-
result, err := a.currentStack.Destroy(a.ctx, opts...)
20+
result, err := pt.currentStack.Destroy(pt.ctx, opts...)
2021
if err != nil {
2122
ptFatalF(t, "failed to destroy: %s", err)
2223
}

pulumitest/execCmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ type cmdOutput struct {
1313
ReturnCode int
1414
}
1515

16-
func (a *PulumiTest) execCmd(t PT, args ...string) cmdOutput {
16+
func (pt *PulumiTest) execCmd(t PT, args ...string) cmdOutput {
1717
t.Helper()
18-
workspace := a.CurrentStack().Workspace()
18+
workspace := pt.CurrentStack().Workspace()
1919
ctx := context.Background()
2020
workdir := workspace.WorkDir()
2121
var env []string

pulumitest/exportStack.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55
)
66

77
// ExportStack exports the current stack state.
8-
func (a *PulumiTest) ExportStack(t PT) apitype.UntypedDeployment {
8+
func (pt *PulumiTest) ExportStack(t PT) apitype.UntypedDeployment {
99
t.Helper()
1010

1111
t.Log("exporting stack")
12-
if a.currentStack == nil {
12+
if pt.currentStack == nil {
1313
ptFatal(t, "no current stack")
1414
}
15-
out, err := a.currentStack.Workspace().ExportStack(a.Context(), a.currentStack.Name())
15+
out, err := pt.currentStack.Workspace().ExportStack(pt.Context(), pt.currentStack.Name())
1616
if err != nil {
1717
ptFatalF(t, "failed to export stack: %s", err)
1818
}

pulumitest/import.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package pulumitest
22

3-
func (a *PulumiTest) Import(t PT, resourceType, resourceName, resourceID string, providerUrn string, args ...string) cmdOutput {
3+
// Import performs a `pulumi import` operation on the current stack.
4+
// The resource type, name, and ID are required. The provider URN is optional.
5+
func (pt *PulumiTest) Import(t PT, resourceType, resourceName, resourceID string, providerUrn string, args ...string) cmdOutput {
46
t.Helper()
57
arguments := []string{
6-
"import", resourceType, resourceName, resourceID, "--yes", "--protect=false", "-s", a.CurrentStack().Name(),
8+
"import", resourceType, resourceName, resourceID, "--yes", "--protect=false", "-s", pt.CurrentStack().Name(),
79
}
810
if providerUrn != "" {
911
arguments = append(arguments, "--provider="+providerUrn)
1012
}
1113
arguments = append(arguments, args...)
12-
ret := a.execCmd(t, arguments...)
14+
ret := pt.execCmd(t, arguments...)
1315
if ret.ReturnCode != 0 {
1416
t.Log(ret.Stdout)
1517
ptFatalF(t, "failed to import resource %s: %s", resourceName, ret.Stderr)

pulumitest/importStack.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55
)
66

77
// ImportStack imports the given stack state into the test's current stack.
8-
func (a *PulumiTest) ImportStack(t PT, source apitype.UntypedDeployment) {
8+
func (pt *PulumiTest) ImportStack(t PT, source apitype.UntypedDeployment) {
99
t.Helper()
1010

1111
t.Log("importing stack")
12-
if a.currentStack == nil {
12+
if pt.currentStack == nil {
1313
ptFatal(t, "no current stack")
1414
}
15-
err := a.currentStack.Workspace().ImportStack(a.Context(), a.currentStack.Name(), source)
15+
err := pt.currentStack.Workspace().ImportStack(pt.Context(), pt.currentStack.Name(), source)
1616
if err != nil {
1717
ptFatalF(t, "failed to import stack: %s", err)
1818
}

0 commit comments

Comments
 (0)