-
Notifications
You must be signed in to change notification settings - Fork 1
/
all_test.go
83 lines (73 loc) · 1.76 KB
/
all_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"math/rand"
"os"
"testing"
"time"
)
var gotvForTesting gotv
func init() {
cacheDir, err := os.MkdirTemp("", "gotv-cache-*")
if err != nil {
panic(err)
}
configDir, err := os.MkdirTemp("", "gotv-config-*")
if err != nil {
panic(err)
}
gotvForTesting, err = bornWithCacheAndConfigDir(cacheDir, configDir)
if err != nil {
panic(err)
}
rand.Seed(time.Now().UnixNano())
}
func Test_sortVersions(t *testing.T) {
var sorted = []string{
"1",
"1.1",
"1.1.1",
"1.5",
"1.10",
"1.11beta1",
"1.11beta2",
"1.11rc1",
"1.11.2",
"1.11.11",
}
for range [100]struct{}{} {
var vs = append([]string{}, sorted...)
for range [32]struct{}{} {
var i, j = rand.Intn(len(vs)), rand.Intn(len(vs))
vs[i], vs[j] = vs[j], vs[i]
}
//t.Log(vs)
var vs2 = append([]string{}, vs...)
sortVersions(vs2)
for i := range sorted {
if vs2[i] != sorted[i] {
t.Errorf("wrong sorting result:\n for %v\n get %v\n", vs, vs2)
}
}
}
}
func Test_parseGoToolchainVersion(t *testing.T) {
var cases = []struct {
v string
tv toolchainVersion
}{
{"1.19", toolchainVersion{kind_Release, "1.19", false}},
{"1.19!", toolchainVersion{kind_Release, "1.19", true}},
{":1.19", toolchainVersion{kind_Alias, "1.19", false}},
{":1.19!", toolchainVersion{kind_Alias, "1.19", true}},
{":tip", toolchainVersion{kind_Alias, "tip", false}},
{":tip!", toolchainVersion{kind_Alias, "tip", true}},
{"bra:1.19", toolchainVersion{kind_Branch, "1.19", false}},
{"tag:1.19", toolchainVersion{kind_Tag, "1.19", false}},
{"rev:12ab", toolchainVersion{kind_Revision, "12ab", false}},
}
for _, c := range cases {
if r := parseGoToolchainVersion(c.v); r != c.tv {
t.Errorf(`parseGoToolchainVersion("%s") != %v, but %v`, c.v, c.tv, r)
}
}
}