Skip to content

Commit 8be0567

Browse files
committed
Fetch the codegen test corpus at test time
The codegen tests read the shared test corpus (schemas, PCL programs, types.json) from tests/testdata/codegen in pulumi/pulumi, previously reached through the submodule. At 11MB across ~2,250 files the corpus is too large to vendor, so `make test_codegen` now fetches it into the gitignored pulumi-language-dotnet/codegen/testdata/upstream directory via a sparse clone of the version pinned in go.mod. A version stamp skips the download when the corpus is already current. The script uses cp instead of rsync so it also runs under Git Bash on Windows.
1 parent f651258 commit 8be0567

6 files changed

Lines changed: 53 additions & 8 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,6 @@ pulumi-resource-testprovider
461461

462462
# Ignore user-provided go.work files.
463463
/go.work
464-
/go.work.sum
464+
/go.work.sum
465+
# Codegen test corpus fetched from pulumi/pulumi by scripts/get_codegen_testdata.sh.
466+
pulumi-language-dotnet/codegen/testdata/upstream/

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,13 @@ test_fast: test_sdk test_sdk_automation test_automation_codegen
135135
test_conformance: build
136136
cd pulumi-language-dotnet && gotestsum -- $(GO_TEST_FILTER_FLAG) --timeout 60m .
137137

138+
## Fetches the codegen test corpus from the pinned pulumi/pulumi version.
139+
.PHONY: codegen_testdata
140+
codegen_testdata:
141+
./scripts/get_codegen_testdata.sh
142+
138143
.PHONY: test_codegen
139-
test_codegen: build
144+
test_codegen: build codegen_testdata
140145
cd pulumi-language-dotnet && gotestsum -- $(GO_TEST_FILTER_FLAG) --timeout 60m ./codegen/...
141146

142147
.PHONY: test_integration

pulumi-language-dotnet/AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Go language host for Pulumi .NET. Invoked by the Pulumi CLI to build, run, and g
99
- `codegen/gen.go` — code generation from Pulumi schemas to C#
1010
- `codegen/gen_program.go` — PCL to C# transpilation
1111
- `codegen/testdata/` — golden files for codegen tests
12+
- `codegen/testdata/upstream/` — gitignored codegen test corpus (schemas, PCL programs) fetched from the pinned pulumi/pulumi version by `make codegen_testdata`
1213
- `testdata/` — conformance test fixtures (projects and SDKs)
1314
- `version/` — version string injected at build time via `-ldflags`
1415

pulumi-language-dotnet/codegen/gen_program_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestGenerateProgram(t *testing.T) {
5454
GenProgram: GenerateProgram,
5555
TestCases: test.PulumiPulumiProgramTests,
5656

57-
InputDirectory: filepath.Join("..", "..", "pulumi", "tests", "testdata", "codegen"),
57+
InputDirectory: filepath.Join("testdata", "upstream", "codegen"),
5858
ResultDirectory: "testdata",
5959
})
6060
}
@@ -73,7 +73,7 @@ func TestGenerateProgramYAML(t *testing.T) {
7373
GenProgram: GenerateProgram,
7474
TestCases: test.PulumiPulumiYAMLProgramTests,
7575

76-
InputDirectory: filepath.Join("..", "..", "pulumi", "tests", "testdata", "codegen"),
76+
InputDirectory: filepath.Join("testdata", "upstream", "codegen"),
7777
ResultDirectory: "testdata",
7878
})
7979
}
@@ -123,7 +123,7 @@ resource "test-organization" "tfe:index/organization:Organization" {
123123
program, diags, err := parseAndBindProgram(t,
124124
source,
125125
"main.pp",
126-
filepath.Join("..", "..", "pulumi", "tests", "testdata", "codegen", "parameterized-schemas"))
126+
filepath.Join("testdata", "upstream", "codegen", "parameterized-schemas"))
127127

128128
require.NoError(t, err)
129129
require.False(t, diags.HasErrors(), "unexpected diags: %v", diags)
@@ -189,7 +189,7 @@ resource "test-organization" "tfe:index/organization:Organization" {
189189
program, diags, err := parseAndBindProgram(t,
190190
source,
191191
"main.pp",
192-
filepath.Join("..", "..", "pulumi", "tests", "testdata", "codegen", "parameterized-schemas"))
192+
filepath.Join("testdata", "upstream", "codegen", "parameterized-schemas"))
193193

194194
require.NoError(t, err)
195195
require.False(t, diags.HasErrors(), "unexpected diags: %v", diags)

pulumi-language-dotnet/codegen/gen_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestGeneratePackage(t *testing.T) {
6767
},
6868
TestCases: filterTests(),
6969

70-
InputDir: filepath.Join("..", "..", "pulumi", "tests", "testdata", "codegen"),
70+
InputDir: filepath.Join("testdata", "upstream", "codegen"),
7171
ResultDir: "testdata",
7272
})
7373
}
@@ -160,5 +160,5 @@ func TestGenerateTypeNames(t *testing.T) {
160160
return func(t schema.Type) string {
161161
return root.typeString(t, "", false, false, false)
162162
}
163-
}, filepath.FromSlash("../../pulumi/tests/testdata/codegen"))
163+
}, filepath.FromSlash("testdata/upstream/codegen"))
164164
}

scripts/get_codegen_testdata.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Fetches the shared codegen test corpus (tests/testdata/codegen) from
4+
# pulumi/pulumi at the version pinned in pulumi-language-dotnet/go.mod into
5+
# pulumi-language-dotnet/codegen/testdata/upstream (gitignored). The download
6+
# is skipped when the corpus is already present at the pinned version.
7+
#
8+
# Uses cp instead of rsync because this also runs under Git Bash on Windows.
9+
10+
set -euo pipefail
11+
12+
cd "$(dirname "$0")/.."
13+
14+
VERSION=$(sed -n 's/^.*github\.com\/pulumi\/pulumi\/sdk\/v3 v//p' pulumi-language-dotnet/go.mod)
15+
if [ -z "$VERSION" ]; then
16+
echo "error: could not determine the pulumi version from pulumi-language-dotnet/go.mod" >&2
17+
exit 1
18+
fi
19+
20+
DEST=pulumi-language-dotnet/codegen/testdata/upstream
21+
if [ -f "$DEST/.version" ] && [ "$(cat "$DEST/.version")" = "v$VERSION" ]; then
22+
exit 0
23+
fi
24+
25+
echo "Fetching the codegen test corpus from pulumi/pulumi v$VERSION"
26+
27+
tmp=$(mktemp -d)
28+
trap 'rm -rf "$tmp"' EXIT
29+
30+
git -c advice.detachedHead=false clone --quiet --depth 1 --branch "v$VERSION" --filter=blob:none --sparse \
31+
https://github.com/pulumi/pulumi.git "$tmp"
32+
git -C "$tmp" sparse-checkout set --no-cone tests/testdata/codegen
33+
34+
rm -rf "$DEST"
35+
mkdir -p "$DEST"
36+
cp -R "$tmp/tests/testdata/codegen" "$DEST/codegen"
37+
echo "v$VERSION" > "$DEST/.version"

0 commit comments

Comments
 (0)