-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acf5d56
commit 649d845
Showing
16 changed files
with
551 additions
and
2 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
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,126 @@ | ||
//go:build !go && !nodejs && !python && !dotnet | ||
// +build !go,!nodejs,!python,!dotnet | ||
|
||
package cloudflare | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/pulumi/providertest" | ||
"github.com/pulumi/providertest/optproviderupgrade" | ||
"github.com/pulumi/providertest/pulumitest" | ||
"github.com/pulumi/providertest/pulumitest/assertpreview" | ||
"github.com/pulumi/providertest/pulumitest/opttest" | ||
"github.com/pulumi/pulumi/sdk/v3/go/auto" | ||
) | ||
|
||
const ( | ||
providerName = "cloudflare" | ||
defaultBaselineVersion = "5.25.0" | ||
) | ||
|
||
var programs = []string{ | ||
"test-programs/index_workerscript", | ||
"test-programs/index_workerskvnamespace", | ||
} | ||
|
||
func TestUpgradeCoverage(t *testing.T) { | ||
providertest.ReportUpgradeCoverage(t) | ||
} | ||
|
||
type UpgradeTestOpts struct { | ||
baselineVersion string | ||
assertFunc func(*testing.T, auto.PreviewResult) | ||
config map[string]string | ||
} | ||
|
||
func WithBaselineVersion(baselineVersion string) func(opts *UpgradeTestOpts) { | ||
return func(opts *UpgradeTestOpts) { | ||
opts.baselineVersion = baselineVersion | ||
} | ||
} | ||
|
||
func WithAssertFunc(assertFunc func(*testing.T, auto.PreviewResult)) func(opts *UpgradeTestOpts) { | ||
return func(opts *UpgradeTestOpts) { | ||
opts.assertFunc = assertFunc | ||
} | ||
} | ||
|
||
func WithConfig(config map[string]string) func(opts *UpgradeTestOpts) { | ||
return func(opts *UpgradeTestOpts) { | ||
opts.config = config | ||
} | ||
} | ||
|
||
func testProviderUpgrade(t *testing.T, dir string, opts ...func(*UpgradeTestOpts)) { | ||
options := &UpgradeTestOpts{} | ||
for _, o := range opts { | ||
o(options) | ||
} | ||
testProviderUpgradeWithOpts(t, dir, options.baselineVersion, options.config, options.assertFunc) | ||
} | ||
|
||
func testProviderUpgradeWithOpts( | ||
t *testing.T, dir, baselineVersion string, config map[string]string, | ||
assertFunction func(*testing.T, auto.PreviewResult), | ||
) { | ||
if testing.Short() { | ||
t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without credentials") | ||
} | ||
cwd, err := os.Getwd() | ||
require.NoError(t, err) | ||
if baselineVersion == "" { | ||
baselineVersion = defaultBaselineVersion | ||
} | ||
test := pulumitest.NewPulumiTest(t, dir, | ||
opttest.DownloadProviderVersion(providerName, baselineVersion), | ||
opttest.LocalProviderPath(providerName, filepath.Join(cwd, "..", "bin")), | ||
) | ||
for k, v := range config { | ||
test.SetConfig(k, v) | ||
} | ||
result := providertest.PreviewProviderUpgrade(test, providerName, baselineVersion, optproviderupgrade.DisableAttach()) | ||
if assertFunction != nil { | ||
assertFunction(t, result) | ||
} else { | ||
assertpreview.HasNoReplacements(t, result) | ||
} | ||
} | ||
|
||
func testProgram(t *testing.T, dir string) { | ||
if testing.Short() { | ||
t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without credentials") | ||
} | ||
cwd, err := os.Getwd() | ||
require.NoError(t, err) | ||
test := pulumitest.NewPulumiTest(t, dir, | ||
opttest.LocalProviderPath(providerName, filepath.Join(cwd, "..", "bin")), | ||
opttest.SkipInstall(), | ||
) | ||
test.SetConfig("cloudflare-account-id", os.Getenv("CLOUDFLARE_ACCOUNT_ID")) | ||
test.SetConfig("cloudflare-zone-id", os.Getenv("CLOUDFLARE_ZONE_ID")) | ||
test.Up() | ||
} | ||
|
||
func TestPrograms(t *testing.T) { | ||
for _, p := range programs { | ||
t.Run(p, func(t *testing.T) { | ||
testProgram(t, p) | ||
}) | ||
} | ||
} | ||
|
||
func TestProgramsUpgrade(t *testing.T) { | ||
for _, p := range programs { | ||
t.Run(p, func(t *testing.T) { | ||
testProviderUpgrade(t, p, WithConfig(map[string]string{ | ||
"cloudflare-account-id": os.Getenv("CLOUDFLARE_ACCOUNT_ID"), | ||
"cloudflare-zone-id": os.Getenv("CLOUDFLARE_ZONE_ID"), | ||
})) | ||
}) | ||
} | ||
} |
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,2 @@ | ||
|
||
/Pulumi.*.yaml |
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,36 @@ | ||
name: index_workerscriptielSrtchSkfd | ||
runtime: yaml | ||
description: "" | ||
config: | ||
cloudflare-account-id: | ||
type: string | ||
default: ACCOUNT_ID | ||
cloudflare-zone-id: | ||
type: string | ||
default: ZONE_ID | ||
pulumi:tags: | ||
value: | ||
pulumi:template: https://www.pulumi.com/ai/api/project/f0297e00-7bf2-4b80-92e9-f7338375bd26.zip | ||
resources: | ||
myWorkerScript: | ||
properties: | ||
name: script${randomName.result} | ||
accountId: ${cloudflare-account-id} | ||
content: | | ||
addEventListener('fetch', event => { | ||
event.respondWith(handleRequest(event.request)) | ||
}) | ||
async function handleRequest(request) { | ||
return new Response('Hello worker!', { | ||
headers: { 'content-type': 'text/plain' }, | ||
}) | ||
} | ||
type: cloudflare:WorkerScript | ||
randomName: | ||
properties: | ||
length: 10 | ||
special: false | ||
upper: false | ||
numeric: false | ||
type: random:RandomString |
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,2 @@ | ||
|
||
/Pulumi.*.yaml |
29 changes: 29 additions & 0 deletions
29
provider/test-programs/index_workerskvnamespace/Pulumi.yaml
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,29 @@ | ||
name: index_workerskvnamespace9PC9vCoap51M | ||
runtime: yaml | ||
description: A minimal Pulumi YAML program that creates a Cloudflare Workers KV Namespace with dependencies | ||
config: | ||
cloudflare-account-id: | ||
type: string | ||
default: ACCOUNT_ID | ||
cloudflare-zone-id: | ||
type: string | ||
default: ZONE_ID | ||
pulumi:tags: | ||
value: | ||
pulumi:template: https://www.pulumi.com/ai/api/project/66a43ab9-9d3d-4d8c-9e07-1d30e5a2ce22.zip | ||
outputs: | ||
kvNamespaceId: ${cloudflareWorkersKvNamespace.id} | ||
resources: | ||
cloudflareWorkersKvNamespace: | ||
properties: | ||
accountId: ${cloudflare-account-id} | ||
title: kv-${randomId.result} | ||
type: cloudflare:WorkersKvNamespace | ||
randomId: | ||
properties: | ||
length: 6 | ||
lower: true | ||
number: false | ||
special: false | ||
upper: false | ||
type: random:RandomString |
Oops, something went wrong.