-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgoxz_test.go
108 lines (104 loc) · 2.2 KB
/
goxz_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package goxz
import (
"context"
"flag"
"io"
"path/filepath"
"reflect"
"sort"
"testing"
)
func TestRun_help(t *testing.T) {
err := Run(context.Background(), []string{"-h"}, io.Discard, io.Discard)
if err != flag.ErrHelp {
t.Errorf("somthing went wrong: %s", err)
}
}
func TestResolvePlatforms(t *testing.T) {
testCases := []struct {
name string
inOS string
inArch string
expect []platform
}{
{
name: "simple",
inOS: "linux",
inArch: "amd64",
expect: []platform{{"linux", "amd64"}},
},
{
name: "comma separated 2 os and whitespece separated 2 arch",
inOS: "linux,windows",
inArch: "amd64 386",
expect: []platform{
{"linux", "amd64"},
{"linux", "386"},
{"windows", "amd64"},
{"windows", "386"},
},
},
{
name: "empty OS",
inOS: "",
inArch: "amd64 386",
expect: []platform{},
},
{
name: "empty Arch",
inOS: "linux",
inArch: "",
expect: []platform{},
},
{
name: "mixed separators",
inOS: "linux ,windows darwin ",
inArch: "amd64 386, arm",
expect: []platform{
{"linux", "amd64"},
{"linux", "386"},
{"linux", "arm"},
{"windows", "amd64"},
{"windows", "386"},
{"windows", "arm"},
{"darwin", "amd64"},
{"darwin", "386"},
{"darwin", "arm"},
},
},
}
for _, tc := range testCases {
o, err := resolvePlatforms(tc.inOS, tc.inArch)
if err != nil {
t.Errorf("error should be nil but: %s", err)
}
out := []platform{}
for _, pf := range o {
out = append(out, *pf)
}
if !reflect.DeepEqual(out, tc.expect) {
t.Errorf("wrong resolvePlatform (%s)\n out: %v\nexpect: %v", tc.name, out, tc.expect)
}
}
}
func TestGatherResources(t *testing.T) {
projDir, _ := filepath.Abs("./testdata")
gx := &goxz{
projDir: projDir,
include: "sample.*",
}
files, err := gx.gatherResources()
if err != nil {
t.Fatal(err)
}
out := make([]string, len(files))
for i, r := range files {
out[i], _ = filepath.Rel(projDir, r)
}
expect := []string{"CREDITS", "LICENSE.txt", "README.md", "sample.conf"}
sort.Strings(expect)
sort.Strings(out)
if !reflect.DeepEqual(out, expect) {
t.Errorf("something went wrong:\n out: %v\nexpect: %v", out, expect)
}
}