Skip to content

Commit 55baa9d

Browse files
committed
revert changes in compile_check_test.go
1 parent e406747 commit 55baa9d

6 files changed

Lines changed: 26 additions & 109 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
go build ./...
5353
go test -short -run ^$$ ./...
5454
55-
go test -v ./internal/test/compilecheck -run '^TestCompileCheck/main_driver/go:1\.19$'
55+
go test -v ./internal/test/compilecheck -run '^TestCompileCheck/go:1\.19$'
5656
- name: Perform CodeQL Analysis
5757
uses: github/codeql-action/analyze@v4.37.2 #immutable
5858
with:

Dockerfile

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,6 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
4747
# Install taskfile
4848
RUN go install github.com/go-task/task/v3/cmd/task@v3.39.2
4949

50-
# Pre-download the Go toolchains used by internal/test/compilecheck so the
51-
# compile check does not download them at runtime (the largest cost of that
52-
# test). The parent Go can fetch and run older toolchain modules, and a single
53-
# linux-amd64 toolchain per version cross-compiles for every GOARCH. Placed
54-
# before "COPY . /mongo-go-driver" so repo changes don't invalidate this layer.
55-
# Keep this list in sync with the GoVersions in
56-
# internal/test/compilecheck/compile_check_test.go.
57-
RUN for v in 1.19.0 1.20.0 1.21.0 1.22.0 1.23.0 1.24.0 1.25.0; do \
58-
GOTOOLCHAIN=go$v go version; \
59-
done
60-
6150
COPY etc/docker_entry.sh /root/docker_entry.sh
6251
COPY --from=libmongocrypt /root/install /root/install
6352

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ tasks:
2323
dir: internal/test/compilecheck
2424
cmds:
2525
- go mod download
26-
- GOTOOLCHAIN=auto go test -v -run '^TestCompileCheck/main_driver/go:1\.19$'
26+
- GOTOOLCHAIN=auto go test -v -run '^TestCompileCheck/go:1\.19$'
2727
build-compile-check-all: bash etc/run-compile-check-test.sh
2828
build-aws-ecs-test: go test -c ./internal/test/aws -o aws.testbin
2929
check-fmt:

ext/awsauth/test/aws_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"testing"
1414

15+
"github.com/aws/aws-sdk-go-v2/aws"
1516
"github.com/aws/aws-sdk-go-v2/config"
1617
"github.com/stretchr/testify/require"
1718
"go.mongodb.org/mongo-driver/ext/awsauth"
@@ -20,6 +21,11 @@ import (
2021
"go.mongodb.org/mongo-driver/v2/mongo/options"
2122
)
2223

24+
var (
25+
_ options.AWSCredentialsProvider = (*awsauth.CredentialsProvider)(nil)
26+
_ options.AWSCredentials = (awsauth.AWSCredentials)(aws.Credentials{})
27+
)
28+
2329
// trackingCredentialsProvider wraps an options.AWSCredentialsProvider and counts calls.
2430
type trackingCredentialsProvider struct {
2531
inner options.AWSCredentialsProvider

ext/awsauth/test/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ replace (
88
)
99

1010
require (
11+
github.com/aws/aws-sdk-go-v2 v1.42.1
1112
github.com/aws/aws-sdk-go-v2/config v1.32.30
1213
github.com/stretchr/testify v1.11.1
1314
go.mongodb.org/mongo-driver/ext/awsauth v0.0.0
1415
go.mongodb.org/mongo-driver/v2 v2.0.0-beta2
1516
)
1617

1718
require (
18-
github.com/aws/aws-sdk-go-v2 v1.42.1 // indirect
1919
github.com/aws/aws-sdk-go-v2/credentials v1.19.29 // indirect
2020
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.30 // indirect
2121
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.30 // indirect

internal/test/compilecheck/compile_check_test.go

Lines changed: 17 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import (
1919
"github.com/testcontainers/testcontainers-go"
2020
)
2121

22-
const (
23-
mainGo = `package main
22+
const mainGo = `package main
2423
2524
import (
2625
"fmt"
@@ -35,30 +34,21 @@ func main() {
3534
fmt.Println(bson.D{{Key: "key", Value: "value"}})
3635
}
3736
`
38-
awsauthGo = `package main
3937

40-
import (
41-
"context"
42-
43-
"github.com/aws/aws-sdk-go-v2/aws"
44-
"go.mongodb.org/mongo-driver/ext/awsauth"
45-
"go.mongodb.org/mongo-driver/v2/mongo"
46-
"go.mongodb.org/mongo-driver/v2/mongo/options"
47-
)
48-
49-
func main() {
50-
provider := aws.CredentialsProviderFunc(func(context.Context) (aws.Credentials, error) {
51-
return aws.Credentials{}, nil
52-
})
53-
awsCredentialProvider := awsauth.NewCredentialsProvider(provider)
54-
credential := options.Credential{
55-
AuthMechanism: "MONGODB-AWS",
56-
AWSCredentialsProvider: awsCredentialProvider,
57-
}
58-
_, _ = mongo.Connect(options.Client().SetAuth(credential))
38+
// goVersions is the list of Go versions to test compilation against.
39+
// To run tests for specific version(s), use the -run flag:
40+
//
41+
// go test -v -run '^TestCompileCheck/go:1.19$'
42+
// go test -v -run '^TestCompileCheck/go:1\.(19|20)$'
43+
var goVersions = []string{
44+
"1.19", // Minimum supported Go version for mongo-driver v2
45+
"1.20",
46+
"1.21",
47+
"1.22",
48+
"1.23",
49+
"1.24",
50+
"1.25", // Test suite Go Version
5951
}
60-
`
61-
)
6252

6353
var architectures = []string{
6454
"386",
@@ -100,8 +90,7 @@ func execContainer(t *testing.T, c testcontainers.Container, cmd string) string
10090
return s
10191
}
10292

103-
// execGo runs a Go command, trying GOTOOLCHAIN=goX.Y.0 first, then the local
104-
// toolchain.
93+
// execGo runs a Go command, trying GOTOOLCHAIN=goX.Y.0 first, then goX.Y.
10594
func execGo(t *testing.T, c testcontainers.Container, cfg *goExecConfig, args ...string) string {
10695
t.Helper()
10796

@@ -119,7 +108,7 @@ func execGo(t *testing.T, c testcontainers.Container, cfg *goExecConfig, args ..
119108
var cmd string
120109
if cfg.version != "" {
121110
primaryCmd := fmt.Sprintf("%s GOTOOLCHAIN=go%s.0 go %s 2>&1", envStr, cfg.version, goArgs)
122-
fallbackCmd := fmt.Sprintf("%s GOTOOLCHAIN=local go %s 2>&1", envStr, goArgs)
111+
fallbackCmd := fmt.Sprintf("%s GOTOOLCHAIN=go%s go %s 2>&1", envStr, cfg.version, goArgs)
123112
cmd = fmt.Sprintf("%s || %s", primaryCmd, fallbackCmd)
124113
} else {
125114
cmd = fmt.Sprintf("%s go %s 2>&1", envStr, goArgs)
@@ -129,56 +118,6 @@ func execGo(t *testing.T, c testcontainers.Container, cfg *goExecConfig, args ..
129118
}
130119

131120
func TestCompileCheck(t *testing.T) {
132-
testCase := []struct {
133-
name string
134-
FileStr string
135-
136-
// GoVersions is the list of Go versions to test compilation against.
137-
// These toolchains are pre-downloaded by the Dockerfile (the image's
138-
// bundled 1.25.x differs from the requested go1.25.0 patch, so it's
139-
// pre-fetched too); keep that RUN in sync with the versions here.
140-
//
141-
// To run tests for specific version(s), use the -run flag:
142-
//
143-
// go test -v -run '^TestCompileCheck/aws_auth/go:1.19$'
144-
// go test -v -run '^TestCompileCheck/main_driver/go:1\.(19|20)$'
145-
GoVersions []string
146-
}{
147-
{
148-
name: "main driver",
149-
FileStr: mainGo,
150-
GoVersions: []string{
151-
"1.19", // Minimum supported Go version for mongo-driver v2
152-
"1.20",
153-
"1.21",
154-
"1.22",
155-
"1.23",
156-
"1.24",
157-
"1.25", // Test suite Go Version
158-
},
159-
},
160-
{
161-
name: "aws auth",
162-
FileStr: awsauthGo,
163-
GoVersions: []string{
164-
"1.20", // Minimum supported Go version for awsauth package
165-
"1.21",
166-
"1.22",
167-
"1.23",
168-
"1.24",
169-
"1.25", // Test suite Go Version
170-
},
171-
},
172-
}
173-
for _, tc := range testCase {
174-
t.Run(tc.name, func(t *testing.T) {
175-
t.Parallel()
176-
compileCheck(t, tc.FileStr, tc.GoVersions)
177-
})
178-
}
179-
}
180-
181-
func compileCheck(t *testing.T, fileStr string, goVersions []string) {
182121
cwd, err := os.Getwd()
183122
require.NoError(t, err)
184123

@@ -193,20 +132,11 @@ func compileCheck(t *testing.T, fileStr string, goVersions []string) {
193132
},
194133
Files: []testcontainers.ContainerFile{
195134
{
196-
Reader: strings.NewReader(fileStr),
135+
Reader: strings.NewReader(mainGo),
197136
ContainerFilePath: "/workspace/main.go",
198137
FileMode: 0o644,
199138
},
200139
},
201-
// Share the Go build cache across both compileCheck containers (the
202-
// "main driver" and "aws auth" cases run in parallel, each in its own
203-
// container). Without this, the per-GOARCH standard-library and driver
204-
// compilation is done twice. Only GOCACHE is shared: do NOT mount over
205-
// /go/pkg/mod, which would hide the Go toolchains baked into the image.
206-
// The Go build cache is safe for concurrent cross-process use.
207-
Mounts: testcontainers.ContainerMounts{
208-
testcontainers.VolumeMount("compilecheck-gocache", "/root/.cache/go-build"),
209-
},
210140
// Entrypoint is set to "tail -f /dev/null" so the container stays running and available to execute multiple shell commands as needed during tests.
211141
// This keeps the container alive and ready for exec calls, rather than immediately exiting.
212142
Entrypoint: []string{"tail", "-f", "/dev/null"},
@@ -227,14 +157,6 @@ func compileCheck(t *testing.T, fileStr string, goVersions []string) {
227157
// Initialize Go module and download dependencies using the test suite Go version.
228158
_ = execGo(t, container, &goExecConfig{version: testSuiteVersion}, "mod", "init", "compilecheck")
229159
_ = execGo(t, container, nil, "mod", "edit", "-replace=go.mongodb.org/mongo-driver/v2=/mongo-go-driver")
230-
_ = execGo(t, container, nil, "mod", "edit", "-replace=go.mongodb.org/mongo-driver/ext/awsauth=/mongo-go-driver/ext/awsauth")
231-
232-
// Pin aws-sdk-go-v2 to the version declared by ext/awsauth/go.mod. Without an
233-
// explicit requirement, "go mod tidy" would add the latest release, which
234-
// requires a newer Go than the minimum this compile check targets. Keep this
235-
// in sync with ext/awsauth/go.mod. Unused for the main-driver case, where
236-
// "go mod tidy" drops it.
237-
_ = execGo(t, container, nil, "mod", "edit", "-require=github.com/aws/aws-sdk-go-v2@v1.28.0")
238160
_ = execGo(t, container, &goExecConfig{version: testSuiteVersion}, "mod", "tidy")
239161

240162
// Set minimum Go version to what the driver claims (first version in our test list).

0 commit comments

Comments
 (0)