Skip to content

Commit 3bfcbbf

Browse files
committed
Add unit test
1 parent 0710ed9 commit 3bfcbbf

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

go/extractor/cli/go-autobuilder/go-autobuilder_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,56 @@ func TestParseGoVersion(t *testing.T) {
3333
}
3434
}
3535
}
36+
37+
func TestGetVersionToInstall(t *testing.T) {
38+
tests := map[versionInfo]string{
39+
// checkForUnsupportedVersions()
40+
41+
// go.mod version below minGoVersion
42+
{"0.0", true, "1.20.3", true}: "",
43+
{"0.0", true, "9999.0", true}: "",
44+
{"0.0", true, "1.2.2", true}: "",
45+
{"0.0", true, "", false}: "",
46+
// go.mod version above maxGoVersion
47+
{"9999.0", true, "1.20.3", true}: "",
48+
{"9999.0", true, "9999.0.1", true}: "",
49+
{"9999.0", true, "1.1", true}: "",
50+
{"9999.0", true, "", false}: "",
51+
// Go installation found with version below minGoVersion
52+
{"1.20", true, "1.2.2", true}: "",
53+
{"1.11", true, "1.2.2", true}: "",
54+
{"", false, "1.2.2", true}: "",
55+
// Go installation found with version above maxGoVersion
56+
{"1.20", true, "9999.0.1", true}: "",
57+
{"1.11", true, "9999.0.1", true}: "",
58+
{"", false, "9999.0.1", true}: "",
59+
60+
// checkForVersionsNotFound()
61+
62+
// Go installation not found, go.mod version in supported range
63+
{"1.20", true, "", false}: "1.20",
64+
{"1.11", true, "", false}: "1.11",
65+
// Go installation not found, go.mod not found
66+
{"", false, "", false}: maxGoVersion,
67+
// Go installation found with version in supported range, go.mod not found
68+
{"", false, "1.11.13", true}: "",
69+
{"", false, "1.20.3", true}: "",
70+
71+
// compareVersions()
72+
73+
// Go installation found with version in supported range, go.mod version in supported range and go.mod version > go installation version
74+
{"1.20", true, "1.11.13", true}: "1.20",
75+
{"1.20", true, "1.12", true}: "1.20",
76+
// Go installation found with version in supported range, go.mod version in supported range and go.mod version <= go installation version
77+
// (Note comparisons ignore the patch version)
78+
{"1.11", true, "1.20", true}: "",
79+
{"1.11", true, "1.20.3", true}: "",
80+
{"1.20", true, "1.20.3", true}: "",
81+
}
82+
for input, expected := range tests {
83+
_, actual := getVersionToInstall(input)
84+
if actual != expected {
85+
t.Errorf("Expected getVersionToInstall(\"%s\") to be \"%s\", but got \"%s\".", input, expected, actual)
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)