-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathplatform_test.go
90 lines (75 loc) · 2.15 KB
/
platform_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
84
85
86
87
88
89
90
package tldr
import (
"testing"
"time"
"github.com/mstruebing/tldr/cache"
"github.com/stretchr/testify/require"
)
const (
remoteURL = "https://tldr.sh/assets/tldr.zip"
ttl = time.Hour * 24 * 7
)
func TestCurrentPlattform(t *testing.T) {
currentPlattform := CurrentPlatform("linux")
if currentPlattform != "linux" {
t.Error("Expected linux, got ", currentPlattform)
}
currentPlattform = CurrentPlatform("LINUX")
if currentPlattform != "linux" {
t.Error("Expected linux, got ", currentPlattform)
}
currentPlattform = CurrentPlatform("darwin")
if currentPlattform != "osx" {
t.Error("Expected osx, got ", currentPlattform)
}
currentPlattform = CurrentPlatform("DARWIN")
if currentPlattform != "osx" {
t.Error("Expected osx, got ", currentPlattform)
}
currentPlattform = CurrentPlatform("sunos")
if currentPlattform != "sunos" {
t.Error("Expected sunos, got ", currentPlattform)
}
currentPlattform = CurrentPlatform("SUNOS")
if currentPlattform != "sunos" {
t.Error("Expected sunos, got ", currentPlattform)
}
currentPlattform = CurrentPlatform("windows")
if currentPlattform != "windows" {
t.Error("Expected windows, got ", currentPlattform)
}
currentPlattform = CurrentPlatform("WINDOWS")
if currentPlattform != "windows" {
t.Error("Expected windows, got ", currentPlattform)
}
}
func TestAvailablePlatforms(t *testing.T) {
tests := []struct {
name string
current string
want []string
wantErr bool
}{
{
name: "linux",
current: "linux",
want: []string{"android", "common", "linux", "osx", "sunos", "windows"},
},
{
name: "stuff",
current: "stuff",
want: []string{"android", "common", "linux", "osx", "sunos", "windows", "stuff"},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
repository, err := cache.NewRepository(remoteURL, ttl)
require.NoError(t, err, "NewRepository() error %v", err)
got, err := AvailablePlatforms(repository, tt.current)
require.NoError(t, err, "AvailablePlatforms() error %v", err)
require.ElementsMatch(t, tt.want, got, "expected available platforms %s, got %s", tt.want, got)
})
}
}