-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgomod_test.go
51 lines (41 loc) · 1.03 KB
/
gomod_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package cron
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var expectedVersion = "go 1.23.0"
func TestAllGoModVersions(t *testing.T) {
var modFiles []string
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
require.NoError(t, err)
if !info.IsDir() && filepath.Base(path) == "go.mod" {
modFiles = append(modFiles, path)
}
return nil
})
require.NoError(t, err)
require.NotEmpty(t, modFiles)
for _, file := range modFiles {
t.Run(file, func(t *testing.T) {
bytes, err := os.ReadFile(file)
require.NoError(t, err)
content := string(bytes)
assert.NotContains(t, content, "toolchain")
contents := strings.Split(content, "\n")
goVersionFound := false
for _, line := range contents {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "go ") {
goVersionFound = true
assert.Equal(t, expectedVersion, line)
break
}
}
assert.True(t, goVersionFound)
})
}
}