Skip to content

Commit

Permalink
Add support for pinning example tests to a specific commit (#105)
Browse files Browse the repository at this point in the history
And pin the failing https://github.com/terraform-aws-modules/terraform-aws-lambda example test to the most recent commit where it succeeds.
  • Loading branch information
justinvp authored Feb 6, 2024
1 parent 0786ca3 commit 153d1fa
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestExample(t *testing.T) {
tests := []struct {
example string
strict bool
commit string
skip stringSet
}{
{
Expand Down Expand Up @@ -282,7 +283,9 @@ func TestExample(t *testing.T) {
},
{
example: "https://github.com/terraform-aws-modules/terraform-aws-lambda",
strict: true,
// TODO[pulumi/pulumi-converter-terraform#104]: `unsupported attribute 'timeouts'` error as of v6.7.1
commit: "a729331518fec8adf232e9a2ad520a5bbc815b26", // v6.7.0
strict: true,
},
{
example: "https://github.com/terraform-aws-modules/terraform-aws-s3-bucket",
Expand Down Expand Up @@ -360,6 +363,19 @@ func TestExample(t *testing.T) {
skip: allLanguages,
},
}

// There could be more than one example in a repo. To keep things simple for now,
// they all must have the same commit specified. Verify that here.
commits := map[string]string{}
for _, tt := range tests {
parsed := parseExample(t, tt.example)
if commit, ok := commits[parsed.cloneURL]; ok {
require.Equal(t, commit, tt.commit, "all examples in %q must use the same commit", parsed.cloneURL)
} else {
commits[parsed.cloneURL] = tt.commit
}
}

for _, tt := range tests {
tt := tt
t.Run(tt.example, func(t *testing.T) {
Expand All @@ -381,6 +397,14 @@ func TestExample(t *testing.T) {
_, _, err = runCommand(t, orgDir, "git", "clone", "--depth", "1", parsed.cloneURL)
require.NoError(t, err, "cloning repo")
}

// If we have a specific commit, use that.
if tt.commit != "" {
_, _, err := runCommand(t, repoDir, "git", "fetch", "--depth", "1", "origin", tt.commit)
require.NoError(t, err, "fetching commit: %s", tt.commit)
_, _, err = runCommand(t, repoDir, "git", "checkout", tt.commit)
require.NoError(t, err, "checking out commit: %s", tt.commit)
}
unlock()

// Test each language.
Expand Down

0 comments on commit 153d1fa

Please sign in to comment.