Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint upstream as a normal unit test #4918

Merged
merged 10 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious what happened here, we ran awsMember call from multiple goroutines?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably because of all the t.Parallel introduced into the tests? Interesting.


// 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)
}
Loading