Skip to content

Commit d0d0045

Browse files
committed
Extract go versions into bash script
and allow compile test on specific versions resolve deprecated BindMount function call remove unwanted files
1 parent 669e669 commit d0d0045

File tree

5 files changed

+28
-77
lines changed

5 files changed

+28
-77
lines changed

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tasks:
1717
- go build ./...
1818
- go build ${BUILD_TAGS} ./...
1919
- task: build-tests
20-
- task: build-compile-check
20+
- task: build-compile-check-all
2121
- task: cross-compile
2222
build-tests: go test -short ${BUILD_TAGS} -run ^$$ ./...
2323
build-compile-check: bash etc/compile_check.sh

etc/run-compile-check-test.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
set -eu
55
set +x
66

7-
echo "Running internal/test/compilecheck"
7+
# Use specified GO_VERSIONS or default to all supported versions.
8+
# To run the compile check tests with specific Go versions, set the GO_VERSIONS environment variable before running this script.
9+
# For example, to use a single version: GO_VERSIONS=1.25 ./etc/run-compile-check-test.sh
10+
# Or to use multiple versions: GO_VERSIONS="1.23,1.24,1.25" ./etc/run-compile-check-test.sh
11+
if [ -z "${GO_VERSIONS:-}" ]; then
12+
GO_VERSIONS="1.19,1.20,1.21,1.22,1.23,1.24,1.25"
13+
fi
14+
export GO_VERSIONS
15+
16+
echo "Running internal/test/compilecheck with Go versions: $GO_VERSIONS"
817
pushd internal/test/compilecheck
918
GOWORK=off go test -timeout 30m -v ./... >>../../../test.suite
1019
popd

internal/cmd/compilecheck/go.mod

Lines changed: 0 additions & 20 deletions
This file was deleted.

internal/cmd/compilecheck/go.sum

Lines changed: 0 additions & 42 deletions
This file was deleted.

internal/test/compilecheck/compile_check_test.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,28 @@ import (
1212
"io"
1313
"os"
1414
"path/filepath"
15+
"strings"
1516
"testing"
1617

18+
"github.com/docker/docker/api/types/container"
1719
"github.com/stretchr/testify/assert"
1820
"github.com/stretchr/testify/require"
1921
"github.com/testcontainers/testcontainers-go"
2022
)
2123

22-
var versions = []string{
23-
"1.19",
24-
"1.20",
25-
"1.21",
26-
"1.22",
27-
"1.23",
28-
"1.24",
29-
"1.25",
24+
func getVersions(t *testing.T) []string {
25+
t.Helper()
26+
27+
env := os.Getenv("GO_VERSIONS")
28+
if env == "" {
29+
t.Skip("GO_VERSIONS environment variable not set")
30+
}
31+
32+
return strings.Split(env, ",")
3033
}
3134

3235
func TestCompileCheck(t *testing.T) {
36+
versions := getVersions(t)
3337
cwd, err := os.Getwd()
3438
require.NoError(t, err)
3539

@@ -43,12 +47,12 @@ func TestCompileCheck(t *testing.T) {
4347
t.Parallel()
4448

4549
req := testcontainers.ContainerRequest{
46-
Image: image,
47-
Cmd: []string{"tail", "-f", "/dev/null"},
48-
Mounts: []testcontainers.ContainerMount{
49-
testcontainers.BindMount(rootDir, "/workspace"),
50-
},
50+
Image: image,
51+
Cmd: []string{"tail", "-f", "/dev/null"},
5152
WorkingDir: "/workspace",
53+
HostConfigModifier: func(hostConfig *container.HostConfig) {
54+
hostConfig.Binds = []string{fmt.Sprintf("%s:/workspace", rootDir)}
55+
},
5256
Env: map[string]string{
5357
"GC": "go",
5458
// Compilation modules are not part of the workspace as testcontainers requires

0 commit comments

Comments
 (0)