Skip to content
Draft
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
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ bin
internal/cmd/faas/awslambda/.aws-sam
internal/cmd/faas/awslambda/events/event.json

# Ignore compiled binaries from the compilecheck
internal/cmd/compilecheck/compilecheck
internal/cmd/compilecheck/compilecheck.so

# Ignore api report files
api-report.md
api-report.txt
Expand Down
4 changes: 1 addition & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ tasks:
- go build ./...
- go build ${BUILD_TAGS} ./...
- task: build-tests
- task: build-compile-check
- task: build-compile-check-all
- task: cross-compile

build-tests: go test -short ${BUILD_TAGS} -run ^$$ ./...

build-compile-check: bash etc/compile_check.sh

build-compile-check-all: bash etc/run-compile-check-test.sh

build-aws-ecs-test: go test -c ./internal/test/aws -o aws.testbin
Expand Down
48 changes: 0 additions & 48 deletions etc/compile_check.sh

This file was deleted.

11 changes: 10 additions & 1 deletion etc/run-compile-check-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
set -eu
set +x

echo "Running internal/test/compilecheck"
# Use specified GO_VERSIONS or default to all supported versions.
# To run the compile check tests with specific Go versions, set the GO_VERSIONS environment variable before running this script.
# For example, to use a single version: GO_VERSIONS=1.25 ./etc/run-compile-check-test.sh
# Or to use multiple versions: GO_VERSIONS="1.23,1.24,1.25" ./etc/run-compile-check-test.sh
if [ -z "${GO_VERSIONS:-}" ]; then
GO_VERSIONS="1.19,1.20,1.21,1.22,1.23,1.24,1.25"
fi
export GO_VERSIONS

echo "Running internal/test/compilecheck with Go versions: $GO_VERSIONS"
pushd internal/test/compilecheck
GOWORK=off go test -timeout 30m -v ./... >>../../../test.suite
popd
1 change: 0 additions & 1 deletion go.work
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use (
./examples/_logger/zap
./examples/_logger/zerolog
./internal/cmd/benchmark
./internal/cmd/compilecheck
./internal/cmd/faas/awslambda/mongodb
./internal/test/compilecheck
./internal/test/goleak
Expand Down
20 changes: 0 additions & 20 deletions internal/cmd/compilecheck/go.mod

This file was deleted.

42 changes: 0 additions & 42 deletions internal/cmd/compilecheck/go.sum

This file was deleted.

5 changes: 0 additions & 5 deletions internal/cmd/compilecheck/go.work

This file was deleted.

24 changes: 0 additions & 24 deletions internal/cmd/compilecheck/main.go

This file was deleted.

99 changes: 77 additions & 22 deletions internal/test/compilecheck/compile_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,52 @@
package main

import (
"bytes"
"context"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"

"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
)

var versions = []string{
"1.19",
"1.20",
"1.21",
"1.22",
"1.23",
"1.24",
"1.25",
const mainGo = `package main

import (
"fmt"

"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)

func main() {
_, _ = mongo.Connect(options.Client())
fmt.Println(bson.D{{Key: "key", Value: "value"}})
}
`

var architectures = []string{"386", "arm", "arm64", "amd64", "ppc64le", "s390x"}

func getVersions(t *testing.T) []string {
t.Helper()

env := os.Getenv("GO_VERSIONS")
if env == "" {
t.Skip("GO_VERSIONS environment variable not set")
}

return strings.Split(env, ",")
}

func TestCompileCheck(t *testing.T) {
versions := getVersions(t)
cwd, err := os.Getwd()
require.NoError(t, err)

Expand All @@ -43,18 +66,17 @@ func TestCompileCheck(t *testing.T) {
t.Parallel()

req := testcontainers.ContainerRequest{
Image: image,
Cmd: []string{"tail", "-f", "/dev/null"},
Mounts: []testcontainers.ContainerMount{
testcontainers.BindMount(rootDir, "/workspace"),
Image: image,
Cmd: []string{"tail", "-f", "/dev/null"},
WorkingDir: "/app",
HostConfigModifier: func(hostConfig *container.HostConfig) {
hostConfig.Binds = []string{fmt.Sprintf("%s:/driver", rootDir)}
},
WorkingDir: "/workspace",
Env: map[string]string{
"GC": "go",
// Compilation modules are not part of the workspace as testcontainers requires
// a version of klauspost/compress not supported by the Go Driver / other modules
// in the workspace.
"GOWORK": "off",
Files: []testcontainers.ContainerFile{
{
ContainerFilePath: "/app/main.go",
Reader: bytes.NewReader([]byte(mainGo)),
},
},
}

Expand All @@ -71,14 +93,47 @@ func TestCompileCheck(t *testing.T) {
require.NoError(t, err)
}()

exitCode, outputReader, err := container.Exec(context.Background(), []string{"bash", "etc/compile_check.sh"})
// Initialize go module and set up replace directive to use local driver.
setupCmds := [][]string{
{"go", "mod", "init", "app"},
{"go", "mod", "edit", "-replace", "go.mongodb.org/mongo-driver/v2=/driver"},
{"go", "mod", "tidy"},
}

for _, cmd := range setupCmds {
exitCode, outputReader, err := container.Exec(context.Background(), cmd)
require.NoError(t, err)

output, err := io.ReadAll(outputReader)
require.NoError(t, err)

require.Equal(t, 0, exitCode, "command %v failed: %s", cmd, output)
}

// Standard build.
exitCode, outputReader, err := container.Exec(context.Background(), []string{"go", "build", "./..."})
require.NoError(t, err)

output, err := io.ReadAll(outputReader)
require.NoError(t, err)

t.Logf("output: %s", output)
assert.Equal(t, 0, exitCode)
require.Equal(t, 0, exitCode, "standard build failed: %s", output)

// Check build with various architectures.
for _, arch := range architectures {
exitCode, outputReader, err := container.Exec(
context.Background(),
[]string{"sh", "-c", fmt.Sprintf("GOOS=linux GOARCH=%s go build ./...", arch)},
)
require.NoError(t, err)

output, err := io.ReadAll(outputReader)
require.NoError(t, err)

assert.Equal(t, 0, exitCode, "build for GOARCH=%s failed: %s", arch, output)
}

t.Logf("compilation checks passed for %s", image)
})
}
}
2 changes: 1 addition & 1 deletion internal/test/compilecheck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.25.0
toolchain go1.25.3

require (
github.com/docker/docker v28.0.0+incompatible
github.com/stretchr/testify v1.10.0
github.com/testcontainers/testcontainers-go v0.35.0
)
Expand All @@ -20,7 +21,6 @@ require (
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v28.0.0+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand Down
Loading