Skip to content
Merged
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
82 changes: 10 additions & 72 deletions internal/test/compilecheck/compile_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,38 @@ package main

import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"golang.org/x/mod/semver"
)

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

const minSupportedVersion = "1.19"
// TODO(GODRIVER-3592): Add "1.25" to the list when Go 1.25 is released.
// Estimated release date is August 2025.
var versions = []string{
"1.19",
"1.20",
"1.21",
"1.22",
"1.23",
"1.24",
}

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

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

versions, err := getDockerGolangImages()
require.NoError(t, err)

for _, version := range versions {
version := version // Capture range variable.

Expand Down Expand Up @@ -85,67 +87,3 @@ func TestCompileCheck(t *testing.T) {
})
}
}

// getDockerGolangImages retrieves the available Golang Docker image tags from
// Docker Hub that are considered valid and meet the specified version
// condition. It returns a slice of version strings in the MajorMinor format and
// an error, if any.
func getDockerGolangImages() ([]string, error) {
// URL to fetch the Golang tags from Docker Hub with a page size of 100
// records.
var url = "https://hub.docker.com/v2/repositories/library/golang/tags?page_size=100"

versionSet := map[string]bool{}
versions := []string{}

// Iteratively fetch and process tags from Docker Hub as long as there is a
// valid next page URL.
for url != "" {
resp, err := http.Get(url)
if err != nil {
return nil, fmt.Errorf("failed to get response from Docker Hub: %w", err)
}

var data struct {
Results []struct {
Name string `json:"name"`
} `json:"results"`
Next string `json:"next"` // URL of the next page for pagination.
}

if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
resp.Body.Close()

return nil, fmt.Errorf("failed to decode response Body from Docker Hub: %w", err)
}

resp.Body.Close()

for _, tag := range data.Results {
// Skip tags that don't start with a digit (typically version numbers).
if len(tag.Name) == 0 || tag.Name[0] < '0' || tag.Name[0] > '9' {
continue
}

// Split the tag name and extract the base version part.
// This handles tags like `1.18.1-alpine` by extracting `1.18.1`.
base := strings.Split(tag.Name, "-")[0]

// Reduce the base version to MajorMinor format (e.g., `v1.18`).
baseMajMin := semver.MajorMinor("v" + base)
if !semver.IsValid(baseMajMin) || versionSet[baseMajMin] {
continue
}

if semver.Compare(baseMajMin, "v"+minSupportedVersion) >= 0 {
versionSet[baseMajMin] = true
versions = append(versions, baseMajMin[1:])
}
}

// Move to the next page of results, set by the `Next` field.
url = data.Next
}

return versions, nil
}
1 change: 0 additions & 1 deletion internal/test/compilecheck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ toolchain go1.23.1
require (
github.com/stretchr/testify v1.10.0
github.com/testcontainers/testcontainers-go v0.35.0
golang.org/x/mod v0.24.0
)

require (
Expand Down
2 changes: 0 additions & 2 deletions internal/test/compilecheck/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
Loading