-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathbuild-environment_test.go
More file actions
62 lines (55 loc) · 2.02 KB
/
build-environment_test.go
File metadata and controls
62 lines (55 loc) · 2.02 KB
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
52
53
54
55
56
57
58
59
60
61
62
package autobuilder
import (
"testing"
"github.com/github/codeql-go/extractor/util"
)
func TestGetVersionToInstall(t *testing.T) {
type inputVersions struct {
modVersion string
envVersion string
}
tests := map[inputVersions]string{
// getVersionWhenGoModVersionNotFound()
{"", ""}: goVersionToInstall.String(),
{"", "1.2.2"}: goVersionToInstall.String(),
{"", "9999.0.1"}: goVersionToInstall.String(),
{"", "1.11.13"}: "",
{"", "1.20.3"}: "",
// getVersionWhenGoModVersionTooHigh()
{"9999.0", ""}: goVersionToInstall.String(),
{"9999.0", "9999.0.1"}: "",
{"9999.0", "1.1"}: goVersionToInstall.String(),
{"9999.0", minGoVersion.String()}: goVersionToInstall.String(),
{"9999.0", goVersionToInstall.String()}: "",
// getVersionWhenGoModVersionTooLow()
{"0.0", ""}: minGoVersion.String(),
{"0.0", "9999.0"}: minGoVersion.String(),
{"0.0", "1.2.2"}: minGoVersion.String(),
{"0.0", "1.20.3"}: "",
// getVersionWhenGoModVersionSupported()
{"1.20", ""}: "1.20",
{"1.11", ""}: "1.11",
{"1.20", "1.2.2"}: "1.20",
{"1.11", "1.2.2"}: "1.11",
{"1.20", "9999.0.1"}: "1.20",
{"1.11", "9999.0.1"}: "1.11",
// go.mod version > go installation version
{"1.20", "1.11.13"}: "1.20",
{"1.20", "1.12"}: "1.20",
// go.mod version <= go installation version (Note comparisons ignore the patch version)
{"1.11", "1.20"}: "",
{"1.11", "1.20.3"}: "",
{"1.20", "1.20.3"}: "",
}
for input, expected := range tests {
_, actual := getVersionToInstall(versionInfo{util.NewSemVer(input.modVersion), util.NewSemVer(input.envVersion)})
if actual != util.NewSemVer(expected) {
t.Errorf("Expected getVersionToInstall(\"%s\") to be \"%s\", but got \"%s\".", input, expected, actual)
}
}
}
func TestMaxGoVersions(t *testing.T) {
if goVersionToInstall.IsNewerThan(maxGoVersion) {
t.Errorf("goVersionToInstall (%s) should not be newer than maxGoVersion (%s).", goVersionToInstall, maxGoVersion)
}
}