Skip to content

Commit acbf2b3

Browse files
GODRIVER-3493 Use semver to compare docker versions to msv
1 parent fd37506 commit acbf2b3

File tree

4 files changed

+13
-41
lines changed

4 files changed

+13
-41
lines changed

etc/compile_check.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,3 @@ function compile_check {
4141
}
4242

4343
compile_check
44-
45-
exit 0

internal/test/compilecheck/compile_check_test.go

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import (
1414
"net/http"
1515
"os"
1616
"path/filepath"
17-
"strconv"
1817
"strings"
1918
"testing"
2019

2120
"github.com/stretchr/testify/assert"
2221
"github.com/stretchr/testify/require"
2322
"github.com/testcontainers/testcontainers-go"
23+
"golang.org/x/mod/semver"
2424
)
2525

2626
const minSupportedVersion = "1.18"
@@ -78,42 +78,6 @@ func TestCompileCheck(t *testing.T) {
7878
}
7979
}
8080

81-
func compareVersions(v1, v2 string) int {
82-
parts1 := strings.Split(v1, ".")
83-
parts2 := strings.Split(v2, ".")
84-
85-
n := len(parts1)
86-
if len(parts2) > n {
87-
n = len(parts2)
88-
}
89-
90-
for i := 0; i < n; i++ {
91-
var num1, num2 int
92-
if i < len(parts2) {
93-
num1, _ = strconv.Atoi(parts1[i])
94-
}
95-
96-
if i < len(parts2) {
97-
num2, _ = strconv.Atoi(parts2[i])
98-
}
99-
100-
if num1 < num2 {
101-
return -1
102-
} else if num1 > num2 {
103-
return 1
104-
}
105-
}
106-
107-
return 0
108-
}
109-
110-
type tagResponse struct {
111-
Results []struct {
112-
Name string `json:"name"`
113-
} `json:"results"`
114-
Next string `json:"next"`
115-
}
116-
11781
func getDockerGolangImages() ([]string, error) {
11882
url := "https://hub.docker.com/v2/repositories/library/golang/tags?page_size=100"
11983

@@ -126,7 +90,13 @@ func getDockerGolangImages() ([]string, error) {
12690

12791
defer resp.Body.Close()
12892

129-
var data tagResponse
93+
var data struct {
94+
Results []struct {
95+
Name string `json:"name"`
96+
} `json:"results"`
97+
Next string `json:"next"`
98+
}
99+
130100
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
131101
return nil, err
132102
}
@@ -156,7 +126,8 @@ func getDockerGolangImages() ([]string, error) {
156126
continue
157127
}
158128

159-
if compareVersions(base, minSupportedVersion) >= 0 {
129+
//if compareVersions(base, minSupportedVersion) >= 0 {
130+
if semver.Compare("v"+base, "v"+minSupportedVersion) >= 0 {
160131
versionSet[base] = true
161132

162133
continue

internal/test/compilecheck/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ replace go.mongodb.org/mongo-driver => ../../../
77
require (
88
github.com/stretchr/testify v1.10.0
99
github.com/testcontainers/testcontainers-go v0.34.0
10+
golang.org/x/mod v0.12.0
1011
)
1112

1213
require (

internal/test/compilecheck/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
137137
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
138138
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
139139
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
140+
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
141+
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
140142
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
141143
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
142144
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=

0 commit comments

Comments
 (0)