Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
revert changes in compile_check_test.go
  • Loading branch information
qingyang-hu committed Jul 28, 2026
commit 55baa9d522ac9d763f7e299a53c4d5dd4f3689f8
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
go build ./...
go test -short -run ^$$ ./...
go test -v ./internal/test/compilecheck -run '^TestCompileCheck/main_driver/go:1\.19$'
go test -v ./internal/test/compilecheck -run '^TestCompileCheck/go:1\.19$'
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4.37.2 #immutable
with:
Expand Down
11 changes: 0 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
# Install taskfile
RUN go install github.com/go-task/task/v3/cmd/task@v3.39.2

# Pre-download the Go toolchains used by internal/test/compilecheck so the
# compile check does not download them at runtime (the largest cost of that
# test). The parent Go can fetch and run older toolchain modules, and a single
# linux-amd64 toolchain per version cross-compiles for every GOARCH. Placed
# before "COPY . /mongo-go-driver" so repo changes don't invalidate this layer.
# Keep this list in sync with the GoVersions in
# internal/test/compilecheck/compile_check_test.go.
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 \
GOTOOLCHAIN=go$v go version; \
done

COPY etc/docker_entry.sh /root/docker_entry.sh
COPY --from=libmongocrypt /root/install /root/install

Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tasks:
dir: internal/test/compilecheck
cmds:
- go mod download
- GOTOOLCHAIN=auto go test -v -run '^TestCompileCheck/main_driver/go:1\.19$'
- GOTOOLCHAIN=auto go test -v -run '^TestCompileCheck/go:1\.19$'
build-compile-check-all: bash etc/run-compile-check-test.sh
build-aws-ecs-test: go test -c ./internal/test/aws -o aws.testbin
check-fmt:
Expand Down
6 changes: 6 additions & 0 deletions ext/awsauth/test/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/ext/awsauth"
Expand All @@ -20,6 +21,11 @@ import (
"go.mongodb.org/mongo-driver/v2/mongo/options"
)

var (
_ options.AWSCredentialsProvider = (*awsauth.CredentialsProvider)(nil)
_ options.AWSCredentials = (awsauth.AWSCredentials)(aws.Credentials{})
)

// trackingCredentialsProvider wraps an options.AWSCredentialsProvider and counts calls.
type trackingCredentialsProvider struct {
inner options.AWSCredentialsProvider
Expand Down
2 changes: 1 addition & 1 deletion ext/awsauth/test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ replace (
)

require (
github.com/aws/aws-sdk-go-v2 v1.42.1
github.com/aws/aws-sdk-go-v2/config v1.32.30
github.com/stretchr/testify v1.11.1
go.mongodb.org/mongo-driver/ext/awsauth v0.0.0
go.mongodb.org/mongo-driver/v2 v2.0.0-beta2
)

require (
github.com/aws/aws-sdk-go-v2 v1.42.1 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.19.29 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.30 // indirect
Expand Down
112 changes: 17 additions & 95 deletions internal/test/compilecheck/compile_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import (
"github.com/testcontainers/testcontainers-go"
)

const (
mainGo = `package main
const mainGo = `package main

import (
"fmt"
Expand All @@ -35,30 +34,21 @@ func main() {
fmt.Println(bson.D{{Key: "key", Value: "value"}})
}
`
awsauthGo = `package main

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"go.mongodb.org/mongo-driver/ext/awsauth"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)

func main() {
provider := aws.CredentialsProviderFunc(func(context.Context) (aws.Credentials, error) {
return aws.Credentials{}, nil
})
awsCredentialProvider := awsauth.NewCredentialsProvider(provider)
credential := options.Credential{
AuthMechanism: "MONGODB-AWS",
AWSCredentialsProvider: awsCredentialProvider,
}
_, _ = mongo.Connect(options.Client().SetAuth(credential))
// goVersions is the list of Go versions to test compilation against.
// To run tests for specific version(s), use the -run flag:
//
// go test -v -run '^TestCompileCheck/go:1.19$'
// go test -v -run '^TestCompileCheck/go:1\.(19|20)$'
var goVersions = []string{
"1.19", // Minimum supported Go version for mongo-driver v2
"1.20",
"1.21",
"1.22",
"1.23",
"1.24",
"1.25", // Test suite Go Version
}
`
)

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

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

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

func TestCompileCheck(t *testing.T) {
testCase := []struct {
name string
FileStr string

// GoVersions is the list of Go versions to test compilation against.
// These toolchains are pre-downloaded by the Dockerfile (the image's
// bundled 1.25.x differs from the requested go1.25.0 patch, so it's
// pre-fetched too); keep that RUN in sync with the versions here.
//
// To run tests for specific version(s), use the -run flag:
//
// go test -v -run '^TestCompileCheck/aws_auth/go:1.19$'
// go test -v -run '^TestCompileCheck/main_driver/go:1\.(19|20)$'
GoVersions []string
}{
{
name: "main driver",
FileStr: mainGo,
GoVersions: []string{
"1.19", // Minimum supported Go version for mongo-driver v2
"1.20",
"1.21",
"1.22",
"1.23",
"1.24",
"1.25", // Test suite Go Version
},
},
{
name: "aws auth",
FileStr: awsauthGo,
GoVersions: []string{
"1.20", // Minimum supported Go version for awsauth package
"1.21",
"1.22",
"1.23",
"1.24",
"1.25", // Test suite Go Version
},
},
}
for _, tc := range testCase {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
compileCheck(t, tc.FileStr, tc.GoVersions)
})
}
}

func compileCheck(t *testing.T, fileStr string, goVersions []string) {
cwd, err := os.Getwd()
require.NoError(t, err)

Expand All @@ -193,20 +132,11 @@ func compileCheck(t *testing.T, fileStr string, goVersions []string) {
},
Files: []testcontainers.ContainerFile{
{
Reader: strings.NewReader(fileStr),
Reader: strings.NewReader(mainGo),
ContainerFilePath: "/workspace/main.go",
FileMode: 0o644,
},
},
// Share the Go build cache across both compileCheck containers (the
// "main driver" and "aws auth" cases run in parallel, each in its own
// container). Without this, the per-GOARCH standard-library and driver
// compilation is done twice. Only GOCACHE is shared: do NOT mount over
// /go/pkg/mod, which would hide the Go toolchains baked into the image.
// The Go build cache is safe for concurrent cross-process use.
Mounts: testcontainers.ContainerMounts{
testcontainers.VolumeMount("compilecheck-gocache", "/root/.cache/go-build"),
},
// Entrypoint is set to "tail -f /dev/null" so the container stays running and available to execute multiple shell commands as needed during tests.
// This keeps the container alive and ready for exec calls, rather than immediately exiting.
Entrypoint: []string{"tail", "-f", "/dev/null"},
Expand All @@ -227,14 +157,6 @@ func compileCheck(t *testing.T, fileStr string, goVersions []string) {
// Initialize Go module and download dependencies using the test suite Go version.
_ = execGo(t, container, &goExecConfig{version: testSuiteVersion}, "mod", "init", "compilecheck")
_ = execGo(t, container, nil, "mod", "edit", "-replace=go.mongodb.org/mongo-driver/v2=/mongo-go-driver")
_ = execGo(t, container, nil, "mod", "edit", "-replace=go.mongodb.org/mongo-driver/ext/awsauth=/mongo-go-driver/ext/awsauth")

// Pin aws-sdk-go-v2 to the version declared by ext/awsauth/go.mod. Without an
// explicit requirement, "go mod tidy" would add the latest release, which
// requires a newer Go than the minimum this compile check targets. Keep this
// in sync with ext/awsauth/go.mod. Unused for the main-driver case, where
// "go mod tidy" drops it.
_ = execGo(t, container, nil, "mod", "edit", "-require=github.com/aws/aws-sdk-go-v2@v1.28.0")
_ = execGo(t, container, &goExecConfig{version: testSuiteVersion}, "mod", "tidy")

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