-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathupdater_test.go
More file actions
69 lines (65 loc) · 2 KB
/
updater_test.go
File metadata and controls
69 lines (65 loc) · 2 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
63
64
65
66
67
68
69
package updater
import (
"testing"
)
func TestResolveChannel(t *testing.T) {
cases := []struct {
flag, current, want string
wantErr bool
}{
{"stable", "1.1.7-next", "stable", false},
{"nightly", "1.1.6", "nightly", false},
{"auto", "1.1.7-next", "nightly", false},
{"auto", "1.1.6", "stable", false},
{"", "1.1.6", "stable", false},
{"bogus", "1.1.6", "", true},
}
for _, c := range cases {
got, err := resolveChannel(c.flag, c.current)
if (err != nil) != c.wantErr {
t.Errorf("resolveChannel(%q,%q) err=%v wantErr=%v", c.flag, c.current, err, c.wantErr)
continue
}
if got != c.want {
t.Errorf("resolveChannel(%q,%q) = %q want %q", c.flag, c.current, got, c.want)
}
}
}
func TestCompareVersions(t *testing.T) {
cases := []struct {
a, b string
want int
}{
{"1.1.6", "1.1.7", -1},
{"1.1.7", "1.1.6", 1},
{"1.1.6", "1.1.6", 0},
{"v1.1.6", "1.1.6", 0},
{"1.1.7-next", "1.1.7", -1}, // semver: prerelease < release
{"1.1.7", "1.1.7-next", 1},
}
for _, c := range cases {
if got := compareVersions(c.a, c.b); got != c.want {
t.Errorf("compareVersions(%q,%q)=%d want %d", c.a, c.b, got, c.want)
}
}
}
func TestShaMatchesRevision(t *testing.T) {
full := "1e0e74cabcdef0123456789abcdef0123456789a"
cases := []struct {
fullSHA, revision string
want bool
}{
{full, "1e0e74c", true}, // goreleaser short
{full, "1E0E74C", true}, // case-insensitive
{full, full, true}, // Makefile full SHA
{full, "deadbee", false}, // different commit
{full, "", false}, // empty -> false (caller already guards)
{full, full + "x", false}, // longer than full SHA
{"short", "shortish", false}, // revision longer than fullSHA
}
for _, c := range cases {
if got := shaMatchesRevision(c.fullSHA, c.revision); got != c.want {
t.Errorf("shaMatchesRevision(%q,%q)=%v want %v", c.fullSHA, c.revision, got, c.want)
}
}
}