Skip to content

Commit 3fde41a

Browse files
authored
Move analysis testing to Go module support (#307)
Reference: golang/go#37054 When this Go module was under heavy development, the analysis testing framework in `golang.org/x/tools` only supported `GOPATH` based resolution. Subsequently, dependencies were vendored and a `vendor` symlink was placed in each of the test case directories. With recent versions of `golang.org/x/tools`, placing a `go.mod` in the `testdata` directory will cause the analysis testing framework to enable Go module support. Only minor import and pathing changes are needed to convert over. Consumers will no longer be burdened with Go module dependencies only needed for testing this Go module.
1 parent 33d67b5 commit 3fde41a

File tree

2,688 files changed

+38878
-807130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,688 files changed

+38878
-807130
lines changed

.github/workflows/release.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ jobs:
2222
go mod tidy
2323
git diff --exit-code -- go.mod go.sum || \
2424
(echo; echo "Unexpected difference in go.mod/go.sum files. Run 'go mod tidy' command or revert any go.mod/go.sum changes and commit."; exit 1)
25-
go mod vendor
26-
git diff --compact-summary --exit-code -- vendor || \
27-
(echo; echo "Unexpected difference in vendor/ directory. Run 'go mod vendor' command or revert any go.mod/go.sum/vendor changes and commit."; exit 1)
2825
go_test:
2926
name: go test
3027
runs-on: ubuntu-latest

.github/workflows/test.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ jobs:
1212
go-version-file: 'go.mod'
1313
- name: go mod
1414
run: |
15-
echo "==> Checking source code with go mod vendor..."
15+
echo "==> Checking source code with go mod tidy..."
1616
go mod tidy
1717
git diff --exit-code -- go.mod go.sum || \
1818
(echo; echo "Unexpected difference in go.mod/go.sum files. Run 'go mod tidy' command or revert any go.mod/go.sum changes and commit."; exit 1)
19-
echo "==> Checking source code with go mod vendor..."
20-
go mod vendor
21-
git diff --compact-summary --exit-code -- vendor || \
22-
(echo; echo "Unexpected difference in vendor/ directory. Run 'go mod vendor' command or revert any go.mod/go.sum/vendor changes and commit."; exit 1)
2319
go_test:
2420
name: go test
2521
runs-on: ubuntu-latest
@@ -28,6 +24,8 @@ jobs:
2824
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
2925
with:
3026
go-version-file: 'go.mod'
27+
# Prevent GOPROXY=off errors for analysistest
28+
- run: for moddir in {,x}passes/*/testdata; do pushd $moddir; go mod download; popd; done
3129
- run: go test ./...
3230
goreleaser:
3331
name: goreleaser

.goreleaser.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ builds:
2424
-
2525
env:
2626
- CGO_ENABLED=0
27-
- GOFLAGS=-mod=vendor
2827
goos:
2928
- darwin
3029
- windows
@@ -40,7 +39,6 @@ builds:
4039
binary: tfproviderlintx
4140
env:
4241
- CGO_ENABLED=0
43-
- GOFLAGS=-mod=vendor
4442
goos:
4543
- darwin
4644
- windows

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ Currently, that means Go **1.21** or later must be used when including this proj
241241

242242
* Create new analyzer in `passes/` (or `xpasses/` for extra checks)
243243
* If the `Analyzer` reports issues, add to `AllChecks` variable in `passes/checks.go` (or `xpasses/checks.go` for extra checks)
244-
* Since the [`analysistest` package](https://godoc.org/golang.org/x/tools/go/analysis/analysistest) does not support Go Modules currently, each analyzer that implements testing must add a symlink to the top level `vendor` directory in the `testdata/src/a` directory. e.g. `ln -s ../../../../../vendor passes/NAME/testdata/src/a/vendor`
245244

246245
### Implementing SuggestedFixes Testing
247246

@@ -256,7 +255,7 @@ import (
256255

257256
func TestAnalyzerFixes(t *testing.T) {
258257
testdata := analysistest.TestData()
259-
analysistest.RunWithSuggestedFixes(t, testdata, Analyzer, "a")
258+
analysistest.RunWithSuggestedFixes(t, testdata, Analyzer, "testdata/src/a")
260259
}
261260
```
262261

go.mod

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,10 @@ go 1.21
44

55
require (
66
github.com/bflad/gopaniccheck v0.1.0
7-
github.com/hashicorp/terraform-plugin-sdk/v2 v2.5.0
87
golang.org/x/tools v0.21.0
98
)
109

1110
require (
12-
cloud.google.com/go v0.65.0 // indirect
13-
cloud.google.com/go/storage v1.10.0 // indirect
14-
github.com/agext/levenshtein v1.2.2 // indirect
15-
github.com/apparentlymart/go-cidr v1.1.0 // indirect
16-
github.com/apparentlymart/go-textseg/v12 v12.0.0 // indirect
17-
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
18-
github.com/aws/aws-sdk-go v1.37.0 // indirect
19-
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
20-
github.com/davecgh/go-spew v1.1.1 // indirect
21-
github.com/fatih/color v1.7.0 // indirect
22-
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
23-
github.com/golang/protobuf v1.4.2 // indirect
24-
github.com/google/go-cmp v0.6.0 // indirect
25-
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
26-
github.com/hashicorp/errwrap v1.0.0 // indirect
27-
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
28-
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
29-
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
30-
github.com/hashicorp/go-getter v1.5.3 // indirect
31-
github.com/hashicorp/go-hclog v0.15.0 // indirect
32-
github.com/hashicorp/go-multierror v1.0.0 // indirect
33-
github.com/hashicorp/go-plugin v1.4.0 // indirect
34-
github.com/hashicorp/go-safetemp v1.0.0 // indirect
35-
github.com/hashicorp/go-uuid v1.0.1 // indirect
36-
github.com/hashicorp/go-version v1.3.0 // indirect
37-
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
38-
github.com/hashicorp/logutils v1.0.0 // indirect
39-
github.com/hashicorp/terraform-exec v0.13.3 // indirect
40-
github.com/hashicorp/terraform-json v0.10.0 // indirect
41-
github.com/hashicorp/terraform-plugin-go v0.2.1 // indirect
42-
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
43-
github.com/jmespath/go-jmespath v0.4.0 // indirect
44-
github.com/jstemmer/go-junit-report v0.9.1 // indirect
45-
github.com/klauspost/compress v1.11.2 // indirect
46-
github.com/mattn/go-colorable v0.1.4 // indirect
47-
github.com/mattn/go-isatty v0.0.10 // indirect
48-
github.com/mitchellh/copystructure v1.0.0 // indirect
49-
github.com/mitchellh/go-homedir v1.1.0 // indirect
50-
github.com/mitchellh/go-testing-interface v1.0.4 // indirect
51-
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
52-
github.com/mitchellh/mapstructure v1.1.2 // indirect
53-
github.com/mitchellh/reflectwalk v1.0.1 // indirect
54-
github.com/oklog/run v1.0.0 // indirect
55-
github.com/ulikunitz/xz v0.5.8 // indirect
56-
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
57-
github.com/zclconf/go-cty v1.8.2 // indirect
58-
go.opencensus.io v0.22.4 // indirect
59-
golang.org/x/crypto v0.23.0 // indirect
60-
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
6111
golang.org/x/mod v0.17.0 // indirect
62-
golang.org/x/net v0.25.0 // indirect
63-
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 // indirect
6412
golang.org/x/sync v0.7.0 // indirect
65-
golang.org/x/sys v0.20.0 // indirect
66-
golang.org/x/text v0.15.0 // indirect
67-
google.golang.org/api v0.34.0 // indirect
68-
google.golang.org/appengine v1.6.6 // indirect
69-
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d // indirect
70-
google.golang.org/grpc v1.32.0 // indirect
71-
google.golang.org/protobuf v1.25.0 // indirect
7213
)

0 commit comments

Comments
 (0)