Skip to content

Commit

Permalink
Lint upstream as a normal unit test (#4918)
Browse files Browse the repository at this point in the history
This removes the last job in `extraTests` by making it a standard unit
test.

Currently the job runs without caching and takes upwards of 30-40
minutes because it re-compiles everything from scratch. This makes it
the long poll when sharding is [turned
on](https://github.com/pulumi/pulumi-aws/actions/runs/12321334449).

By running with the rest of our tests it can benefit from caching.
Locally the test takes only ~20s.

This is run during unit tests, which still take about ~5 minutes before
and after this change. They're actually slightly faster because I
parallelized some of them while I was in here.
  • Loading branch information
blampe authored Dec 16, 2024
1 parent ccd48fb commit df65048
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 58 deletions.
29 changes: 0 additions & 29 deletions .ci-mgmt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,3 @@ actions:
role-to-assume: ${{ secrets.AWS_CI_ROLE_ARN }}
- name: Make upstream
run: make upstream

extraTests:

upstream_lint:
name: Run upstream provider-lint
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
swap-storage: false
tool-cache: false
- name: Checkout Repo
uses: actions/checkout@v4
with:
ref: ${{ env.PR_COMMIT_SHA }}
submodules: true
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.23.x"
cache: false
- name: Prepare local workspace
run: make prepare_local_workspace
- name: upstream lint
run: |
cd upstream
make provider-lint
27 changes: 0 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,3 @@ jobs:
- go
- java
testTarget: [local]
upstream_lint:
name: Run upstream provider-lint
runs-on: ubuntu-latest
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
swap-storage: false
tool-cache: false
- name: Checkout Repo
uses: actions/checkout@v4
with:
ref: ${{ env.PR_COMMIT_SHA }}
submodules: true
- name: Install Go
uses: actions/setup-go@v5
with:
cache: false
go-version: 1.23.x
- name: Prepare local workspace
run: make prepare_local_workspace
- name: upstream lint
run: |
cd upstream
make provider-lint
timeout-minutes: 60

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Bryce Lampe <[email protected]>
Date: Fri, 13 Dec 2024 13:44:02 -0800
Subject: [PATCH] Speed up providerlint by re-using build cache and ignoring
tests


diff --git a/GNUmakefile b/GNUmakefile
index 9b4adecff8..32137c8919 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -326,9 +326,10 @@ prereq-go: ## If $(GO_VER) is not installed, install it

provider-lint: ## [CI] ProviderLint Checks / providerlint
@echo "make: ProviderLint Checks / providerlint..."
- @cd .ci/providerlint && go install -buildvcs=false .
- @providerlint \
+ @cd .ci/providerlint && go build -buildvcs=false .
+ @.ci/providerlint/providerlint \
-c 1 \
+ -test=false \
-AT001.ignored-filename-suffixes=_data_source_test.go \
-AWSAT006=false \
-AWSR002=false \
2 changes: 2 additions & 0 deletions provider/cmd/pulumi-tfgen-aws/wafv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

func TestReplaceWafV2TypesWithRecursive(t *testing.T) {
t.Parallel()

spec := schema.PackageSpec{
Types: map[string]schema.ComplexTypeSpec{
// Root statement - keep it.
Expand Down
4 changes: 4 additions & 0 deletions provider/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
)

func TestCheckConfigWithUnknownKeys(t *testing.T) {
t.Parallel()

// Double checking that this is a failure, but no longer over-fitting the test on the exact
// error message. See pulumi/pulumi-terraform-bridge codebase instead for controlling the
// generated error message.
Expand Down Expand Up @@ -57,6 +59,8 @@ func TestCheckConfigWithUnknownKeys(t *testing.T) {
}

func TestCheckConfigRunsUpstreamValidators(t *testing.T) {
t.Parallel()

replaySequence(t, strings.ReplaceAll(`
[{
"method": "/pulumirpc.ResourceProvider/CheckConfig",
Expand Down
2 changes: 2 additions & 0 deletions provider/diag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

func TestFormatDiags(t *testing.T) {
t.Parallel()

type testCase struct {
name string
config diag.Diagnostics
Expand Down
4 changes: 4 additions & 0 deletions provider/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
//
// See also pulumi/pulumi-aws#3650.
func TestRegressLandingZoneDiff(t *testing.T) {
t.Parallel()

event := `
[{
"method": "/pulumirpc.ResourceProvider/Diff",
Expand Down Expand Up @@ -66,6 +68,8 @@ func TestRegressLandingZoneDiff(t *testing.T) {
}

func TestRegress1738(t *testing.T) {
t.Parallel()

containerDefinitionsOld := `
[
{
Expand Down
4 changes: 4 additions & 0 deletions provider/enum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestInstanceTypeName(t *testing.T) {
t.Parallel()

type testCase struct {
Value string
Name string
Expand All @@ -34,6 +36,8 @@ func TestInstanceTypeName(t *testing.T) {
}

func TestInstanceTypeNameErr(t *testing.T) {
t.Parallel()

testCases := []string{
"a1.metal.pc",
}
Expand Down
4 changes: 3 additions & 1 deletion provider/fast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ func init() {
version.Version = "1.2.4"
}

func TestProvider(_ *testing.T) {
func TestProvider(t *testing.T) {
t.Parallel()

Provider()
}

Expand Down
2 changes: 2 additions & 0 deletions provider/pkg/batch/compute_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
)

func TestComputeEnvironmentTransformFromState(t *testing.T) {
t.Parallel()

ctx := context.Background()
pm := resource.PropertyMap{
"computeResources": resource.NewObjectProperty(resource.PropertyMap{
Expand Down
2 changes: 2 additions & 0 deletions provider/pkg/minimalschema/minimalschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
)

func TestNoDanglingReferencesInLightSchema(t *testing.T) {
t.Parallel()

// Check that minimal schema has no dangling references.
bytes, err := os.ReadFile(minimalSchemaFile)
require.NoError(t, err)
Expand Down
5 changes: 5 additions & 0 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path/filepath"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"unicode"
Expand Down Expand Up @@ -493,9 +494,13 @@ var namespaceMap = map[string]string{
"aws": "Aws",
}

var _nslock = sync.Mutex{}

// awsMember manufactures a type token for the AWS package and the given module, file name, and type.
func awsMember(moduleTitle string, fn string, mem string) tokens.ModuleMember {
moduleName := strings.ToLower(moduleTitle)
_nslock.Lock()
defer _nslock.Unlock()
namespaceMap[moduleName] = moduleTitle
if fn != "" {
moduleName += "/" + fn
Expand Down
10 changes: 9 additions & 1 deletion provider/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"context"
"testing"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/stretchr/testify/assert"
)

func TestParseDuration(t *testing.T) {
t.Parallel()

for _, v := range []string{
"1",
"60",
Expand All @@ -29,6 +31,8 @@ func TestParseDuration(t *testing.T) {
}

func TestHasNonComputedTagsAndTagsAllOptimized(t *testing.T) {
t.Parallel()

p := Provider()
p.P.ResourcesMap().Range(func(key string, value shim.Resource) bool {
actual := hasNonComputedTagsAndTagsAllOptimized(key, value)
Expand All @@ -50,6 +54,8 @@ func TestHasNonComputedTagsAndTagsAllOptimized(t *testing.T) {
}

func TestHasOptionalOrRequiredNamePropertyOptimized(t *testing.T) {
t.Parallel()

p := Provider()
p.P.ResourcesMap().Range(func(key string, value shim.Resource) bool {
actual := hasOptionalOrRequiredNameProperty(p.P, key)
Expand All @@ -67,6 +73,8 @@ func TestHasOptionalOrRequiredNamePropertyOptimized(t *testing.T) {
}
}
func TestExtractTags(t *testing.T) {
t.Parallel()

tests := []struct {
name string
vars resource.PropertyMap
Expand Down
2 changes: 2 additions & 0 deletions provider/shim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

// This checks that any runtime checks in the underlying provider (with patches) are passed.
func TestProviderShim(t *testing.T) {
t.Parallel()

ctx := context.Background()
_, err := shim.NewUpstreamProvider(ctx)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions provider/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
)

func TestApplyTags(t *testing.T) {
t.Parallel()

ctx := context.Background()

type gen = *rapid.Generator[resource.PropertyValue]
Expand Down Expand Up @@ -221,6 +223,8 @@ func TestApplyTags(t *testing.T) {
}

func TestApplyTagsOutputs(t *testing.T) {
t.Parallel()

ctx := context.Background()

type gen = *rapid.Generator[resource.PropertyValue]
Expand Down Expand Up @@ -402,6 +406,8 @@ func TestApplyTagsOutputs(t *testing.T) {
}

func TestAddingEmptyTagProducesChangeDiff(t *testing.T) {
t.Parallel()

replayEvent := `
[
{
Expand Down Expand Up @@ -498,6 +504,8 @@ func TestAddingEmptyTagProducesChangeDiff(t *testing.T) {
}

func TestTagsAllNoLongerComputed(t *testing.T) {
t.Parallel()

p := Provider().P
p.ResourcesMap().Range(func(key string, res tfshim.Resource) bool {
tagsAll, ok := res.Schema().GetOk("tags_all")
Expand Down
39 changes: 39 additions & 0 deletions provider/upstream_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package provider

import (
"os"
"os/exec"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestUpstreamLint(t *testing.T) {
t.Parallel()

cmd := exec.Command("make", "provider-lint")
cmd.Dir = "../upstream"

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err := cmd.Start()
require.NoError(t, err)

err = cmd.Wait()
assert.NoError(t, err)
}

0 comments on commit df65048

Please sign in to comment.