Skip to content

Commit 4082d8f

Browse files
GODRIVER-3493 Test why codeql is breaking
1 parent 42d160e commit 4082d8f

File tree

1 file changed

+117
-134
lines changed

1 file changed

+117
-134
lines changed

internal/test/compilecheck/compile_check_test.go

Lines changed: 117 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -6,137 +6,120 @@
66

77
package main
88

9-
import (
10-
"context"
11-
"encoding/json"
12-
"fmt"
13-
"io"
14-
"net/http"
15-
"os"
16-
"path/filepath"
17-
"strings"
18-
"testing"
19-
20-
"github.com/stretchr/testify/assert"
21-
"github.com/stretchr/testify/require"
22-
"github.com/testcontainers/testcontainers-go"
23-
"golang.org/x/mod/semver"
24-
)
25-
26-
const minSupportedVersion = "1.18"
27-
28-
func TestCompileCheck(t *testing.T) {
29-
return
30-
cwd, err := os.Getwd()
31-
require.NoError(t, err)
32-
33-
rootDir := filepath.Dir(filepath.Dir(filepath.Dir(cwd)))
34-
35-
versions, err := getDockerGolangImages()
36-
require.NoError(t, err)
37-
38-
for _, version := range versions {
39-
version := version // Capture range variable.
40-
41-
image := fmt.Sprintf("golang:%s", version)
42-
t.Run(image, func(t *testing.T) {
43-
t.Parallel()
44-
45-
req := testcontainers.ContainerRequest{
46-
Image: image,
47-
Cmd: []string{"tail", "-f", "/dev/null"},
48-
Mounts: []testcontainers.ContainerMount{
49-
testcontainers.BindMount(rootDir, "/workspace"),
50-
},
51-
WorkingDir: "/workspace",
52-
Env: map[string]string{
53-
"GO_VERSION": version,
54-
},
55-
}
56-
57-
genReq := testcontainers.GenericContainerRequest{
58-
ContainerRequest: req,
59-
Started: true,
60-
}
61-
62-
container, err := testcontainers.GenericContainer(context.Background(), genReq)
63-
require.NoError(t, err)
64-
65-
defer func() {
66-
err := container.Terminate(context.Background())
67-
require.NoError(t, err)
68-
}()
69-
70-
exitCode, outputReader, err := container.Exec(context.Background(), []string{"bash", "etc/compile_check.sh"})
71-
require.NoError(t, err)
72-
73-
output, err := io.ReadAll(outputReader)
74-
require.NoError(t, err)
75-
76-
t.Logf("output: %s", output)
77-
assert.Equal(t, 0, exitCode)
78-
})
79-
}
80-
}
81-
82-
// getDockerGolangImages retrieves the available Golang Docker image tags from
83-
// Docker Hub that are considered valid and meet the specified version
84-
// condition. It returns a slice of version strings in the MajorMinor format and
85-
// an error, if any.
86-
func getDockerGolangImages() ([]string, error) {
87-
// URL to fetch the Golang tags from Docker Hub with a page size of 100
88-
// records.
89-
var url = "https://hub.docker.com/v2/repositories/library/golang/tags?page_size=100"
90-
91-
versionSet := map[string]bool{}
92-
versions := []string{}
93-
94-
// Iteratively fetch and process tags from Docker Hub as long as there is a
95-
// valid next page URL.
96-
for url != "" {
97-
resp, err := http.Get(url)
98-
if err != nil {
99-
return nil, fmt.Errorf("failed to get response from Docker Hub: %w", err)
100-
}
101-
102-
var data struct {
103-
Results []struct {
104-
Name string `json:"name"`
105-
} `json:"results"`
106-
Next string `json:"next"` // URL of the next page for pagination.
107-
}
108-
109-
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
110-
return nil, fmt.Errorf("failed to decode response Body from Docker Hub: %w", err)
111-
}
112-
113-
resp.Body.Close()
114-
115-
for _, tag := range data.Results {
116-
// Skip tags that don't start with a digit (typically version numbers).
117-
if len(tag.Name) == 0 || tag.Name[0] < '0' || tag.Name[0] > '9' {
118-
continue
119-
}
120-
121-
// Split the tag name and extract the base version part.
122-
// This handles tags like `1.18.1-alpine` by extracting `1.18.1`.
123-
base := strings.Split(tag.Name, "-")[0]
124-
125-
// Reduce the base version to MajorMinor format (e.g., `v1.18`).
126-
baseMajMin := semver.MajorMinor("v" + base)
127-
if !semver.IsValid(baseMajMin) || versionSet[baseMajMin] {
128-
continue
129-
}
130-
131-
if semver.Compare(baseMajMin, "v"+minSupportedVersion) >= 0 {
132-
versionSet[baseMajMin] = true
133-
versions = append(versions, baseMajMin[1:])
134-
}
135-
}
136-
137-
// Move to the next page of results, set by the `Next` field.
138-
url = data.Next
139-
}
140-
141-
return versions, nil
142-
}
9+
//const minSupportedVersion = "1.18"
10+
//
11+
//func TestCompileCheck(t *testing.T) {
12+
// return
13+
// cwd, err := os.Getwd()
14+
// require.NoError(t, err)
15+
//
16+
// rootDir := filepath.Dir(filepath.Dir(filepath.Dir(cwd)))
17+
//
18+
// versions, err := getDockerGolangImages()
19+
/// require.NoError(t, err)
20+
//
21+
// for _, version := range versions {
22+
// version := version // Capture range variable.
23+
//
24+
// image := fmt.Sprintf("golang:%s", version)
25+
// t.Run(image, func(t *testing.T) {
26+
// t.Parallel()
27+
//
28+
// req := testcontainers.ContainerRequest{
29+
// Image: image,
30+
// Cmd: []string{"tail", "-f", "/dev/null"},
31+
// Mounts: []testcontainers.ContainerMount{
32+
// testcontainers.BindMount(rootDir, "/workspace"),
33+
// },
34+
// WorkingDir: "/workspace",
35+
// Env: map[string]string{
36+
// "GO_VERSION": version,
37+
// },
38+
// }
39+
//
40+
// genReq := testcontainers.GenericContainerRequest{
41+
// ContainerRequest: req,
42+
// Started: true,
43+
// }
44+
//
45+
// container, err := testcontainers.GenericContainer(context.Background(), genReq)
46+
// require.NoError(t, err)
47+
//
48+
// defer func() {
49+
// err := container.Terminate(context.Background())
50+
// require.NoError(t, err)
51+
// }()
52+
//
53+
// exitCode, outputReader, err := container.Exec(context.Background(), []string{"bash", "etc/compile_check.sh"})
54+
// require.NoError(t, err)
55+
//
56+
// output, err := io.ReadAll(outputReader)
57+
// require.NoError(t, err)
58+
//
59+
// t.Logf("output: %s", output)
60+
// assert.Equal(t, 0, exitCode)
61+
// })
62+
// }
63+
//}
64+
//
65+
//// getDockerGolangImages retrieves the available Golang Docker image tags from
66+
//// Docker Hub that are considered valid and meet the specified version
67+
//// condition. It returns a slice of version strings in the MajorMinor format and
68+
//// an error, if any.
69+
//func getDockerGolangImages() ([]string, error) {
70+
// // URL to fetch the Golang tags from Docker Hub with a page size of 100
71+
// // records.
72+
// var url = "https://hub.docker.com/v2/repositories/library/golang/tags?page_size=100"
73+
//
74+
// versionSet := map[string]bool{}
75+
// versions := []string{}
76+
//
77+
// // Iteratively fetch and process tags from Docker Hub as long as there is a
78+
// // valid next page URL.
79+
// for url != "" {
80+
// resp, err := http.Get(url)
81+
// if err != nil {
82+
// return nil, fmt.Errorf("failed to get response from Docker Hub: %w", err)
83+
// }
84+
//
85+
// var data struct {
86+
// Results []struct {
87+
// Name string `json:"name"`
88+
// } `json:"results"`
89+
// Next string `json:"next"` // URL of the next page for pagination.
90+
// }
91+
//
92+
// if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
93+
// return nil, fmt.Errorf("failed to decode response Body from Docker Hub: %w", err)
94+
// }
95+
//
96+
// resp.Body.Close()
97+
//
98+
// for _, tag := range data.Results {
99+
// // Skip tags that don't start with a digit (typically version numbers).
100+
// if len(tag.Name) == 0 || tag.Name[0] < '0' || tag.Name[0] > '9' {
101+
// continue
102+
// }
103+
//
104+
// // Split the tag name and extract the base version part.
105+
// // This handles tags like `1.18.1-alpine` by extracting `1.18.1`.
106+
// base := strings.Split(tag.Name, "-")[0]
107+
//
108+
// // Reduce the base version to MajorMinor format (e.g., `v1.18`).
109+
// baseMajMin := semver.MajorMinor("v" + base)
110+
// if !semver.IsValid(baseMajMin) || versionSet[baseMajMin] {
111+
// continue
112+
// }
113+
//
114+
// if semver.Compare(baseMajMin, "v"+minSupportedVersion) >= 0 {
115+
// versionSet[baseMajMin] = true
116+
// versions = append(versions, baseMajMin[1:])
117+
// }
118+
// }
119+
//
120+
// // Move to the next page of results, set by the `Next` field.
121+
// url = data.Next
122+
// }
123+
//
124+
// return versions, nil
125+
//}

0 commit comments

Comments
 (0)