Skip to content

Commit 4a4e6dc

Browse files
authored
Merge pull request #2108 from matthewdale/godriver3591-fix-compilecheck-ver
GODRIVER-3591 Use a static list of Go versions in the compile check.
2 parents ff50112 + b4b479a commit 4a4e6dc

File tree

3 files changed

+10
-75
lines changed

3 files changed

+10
-75
lines changed

internal/test/compilecheck/compile_check_test.go

Lines changed: 10 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,38 @@ package main
88

99
import (
1010
"context"
11-
"encoding/json"
1211
"fmt"
1312
"io"
14-
"net/http"
1513
"os"
1614
"path/filepath"
17-
"strings"
1815
"testing"
1916

2017
"github.com/stretchr/testify/assert"
2118
"github.com/stretchr/testify/require"
2219
"github.com/testcontainers/testcontainers-go"
23-
"golang.org/x/mod/semver"
2420
)
2521

2622
// TODO(GODRIVER-3515): This module cannot be included in the workspace since it
2723
// requires a version of klauspost/compress that is not compatible with the Go
2824
// Driver. Must use GOWORK=off to run this test.
2925

30-
const minSupportedVersion = "1.19"
26+
// TODO(GODRIVER-3592): Add "1.25" to the list when Go 1.25 is released.
27+
// Estimated release date is August 2025.
28+
var versions = []string{
29+
"1.19",
30+
"1.20",
31+
"1.21",
32+
"1.22",
33+
"1.23",
34+
"1.24",
35+
}
3136

3237
func TestCompileCheck(t *testing.T) {
3338
cwd, err := os.Getwd()
3439
require.NoError(t, err)
3540

3641
rootDir := filepath.Dir(filepath.Dir(filepath.Dir(cwd)))
3742

38-
versions, err := getDockerGolangImages()
39-
require.NoError(t, err)
40-
4143
for _, version := range versions {
4244
version := version // Capture range variable.
4345

@@ -85,67 +87,3 @@ func TestCompileCheck(t *testing.T) {
8587
})
8688
}
8789
}
88-
89-
// getDockerGolangImages retrieves the available Golang Docker image tags from
90-
// Docker Hub that are considered valid and meet the specified version
91-
// condition. It returns a slice of version strings in the MajorMinor format and
92-
// an error, if any.
93-
func getDockerGolangImages() ([]string, error) {
94-
// URL to fetch the Golang tags from Docker Hub with a page size of 100
95-
// records.
96-
var url = "https://hub.docker.com/v2/repositories/library/golang/tags?page_size=100"
97-
98-
versionSet := map[string]bool{}
99-
versions := []string{}
100-
101-
// Iteratively fetch and process tags from Docker Hub as long as there is a
102-
// valid next page URL.
103-
for url != "" {
104-
resp, err := http.Get(url)
105-
if err != nil {
106-
return nil, fmt.Errorf("failed to get response from Docker Hub: %w", err)
107-
}
108-
109-
var data struct {
110-
Results []struct {
111-
Name string `json:"name"`
112-
} `json:"results"`
113-
Next string `json:"next"` // URL of the next page for pagination.
114-
}
115-
116-
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
117-
resp.Body.Close()
118-
119-
return nil, fmt.Errorf("failed to decode response Body from Docker Hub: %w", err)
120-
}
121-
122-
resp.Body.Close()
123-
124-
for _, tag := range data.Results {
125-
// Skip tags that don't start with a digit (typically version numbers).
126-
if len(tag.Name) == 0 || tag.Name[0] < '0' || tag.Name[0] > '9' {
127-
continue
128-
}
129-
130-
// Split the tag name and extract the base version part.
131-
// This handles tags like `1.18.1-alpine` by extracting `1.18.1`.
132-
base := strings.Split(tag.Name, "-")[0]
133-
134-
// Reduce the base version to MajorMinor format (e.g., `v1.18`).
135-
baseMajMin := semver.MajorMinor("v" + base)
136-
if !semver.IsValid(baseMajMin) || versionSet[baseMajMin] {
137-
continue
138-
}
139-
140-
if semver.Compare(baseMajMin, "v"+minSupportedVersion) >= 0 {
141-
versionSet[baseMajMin] = true
142-
versions = append(versions, baseMajMin[1:])
143-
}
144-
}
145-
146-
// Move to the next page of results, set by the `Next` field.
147-
url = data.Next
148-
}
149-
150-
return versions, nil
151-
}

internal/test/compilecheck/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ toolchain go1.23.1
77
require (
88
github.com/stretchr/testify v1.10.0
99
github.com/testcontainers/testcontainers-go v0.35.0
10-
golang.org/x/mod v0.24.0
1110
)
1211

1312
require (

internal/test/compilecheck/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
139139
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
140140
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
141141
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
142-
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
143-
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
144142
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
145143
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
146144
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=

0 commit comments

Comments
 (0)