1
1
package toolchain
2
2
3
- import "testing"
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/github/codeql-go/extractor/util"
7
+ )
4
8
5
9
func TestParseGoVersion (t * testing.T ) {
6
10
tests := map [string ]string {
@@ -16,9 +20,41 @@ func TestParseGoVersion(t *testing.T) {
16
20
}
17
21
18
22
func TestHasGoVersion (t * testing.T ) {
19
- if HasGoVersion ("1.21" ) {
20
- t .Error ("Expected HasGoVersion(\" 1.21\" ) to be false, but got true" )
23
+ versions := []string {"1.21" , "v1.22" , "1.22.3" , "v1.21rc4" }
24
+
25
+ // All versions should be unknown.
26
+ for _ , version := range versions {
27
+ if HasGoVersion (version ) {
28
+ t .Errorf ("Expected HasGoVersion(\" %s\" ) to be false, but got true" , version )
29
+ }
30
+
31
+ if HasGoVersion (util .FormatSemVer (version )) {
32
+ t .Errorf ("Expected HasGoVersion(\" %s\" ) to be false, but got true" , util .FormatSemVer (version ))
33
+ }
34
+
35
+ if HasGoVersion (util .UnformatSemVer (version )) {
36
+ t .Errorf ("Expected HasGoVersion(\" %s\" ) to be false, but got true" , util .UnformatSemVer (version ))
37
+ }
38
+
39
+ // Add the version in preparation for the next part of the test.
40
+ addGoVersion (version )
21
41
}
42
+
43
+ // Now we should have all of the versions.
44
+ for _ , version := range versions {
45
+ if ! HasGoVersion (version ) {
46
+ t .Errorf ("Expected HasGoVersion(\" %s\" ) to be true, but got false" , version )
47
+ }
48
+
49
+ if ! HasGoVersion (util .FormatSemVer (version )) {
50
+ t .Errorf ("Expected HasGoVersion(\" %s\" ) to be true, but got false" , util .FormatSemVer (version ))
51
+ }
52
+
53
+ if ! HasGoVersion (util .UnformatSemVer (version )) {
54
+ t .Errorf ("Expected HasGoVersion(\" %s\" ) to be true, but got false" , util .UnformatSemVer (version ))
55
+ }
56
+ }
57
+
22
58
}
23
59
24
60
func testGoVersionToSemVer (t * testing.T , goVersion string , expectedSemVer string ) {
0 commit comments