-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_test.go
More file actions
58 lines (55 loc) · 1.18 KB
/
Copy pathutils_test.go
File metadata and controls
58 lines (55 loc) · 1.18 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
package main
import (
"reflect"
"testing"
)
func TestSplitArgs(t *testing.T) {
tests := []struct {
input string
expected []string
wantErr bool
}{
{
input: `get`,
expected: []string{"get"},
wantErr: false,
},
{
input: `get subpath`,
expected: []string{"get", "subpath"},
wantErr: false,
},
{
input: `post --content "{\"id\": 1}"`,
expected: []string{"post", "--content", `{"id": 1}`},
wantErr: false,
},
{
input: `set header "Authorization" "Bearer 12345"`,
expected: []string{"set", "header", "Authorization", "Bearer 12345"},
wantErr: false,
},
{
input: `post -c '{"name": "hello"}'`,
expected: []string{"post", "-c", `{"name": "hello"}`},
wantErr: false,
},
{
input: `post --content "unclosed`,
expected: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got, err := splitArgs(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("splitArgs() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr && !reflect.DeepEqual(got, tt.expected) {
t.Errorf("splitArgs() = %v, want %v", got, tt.expected)
}
})
}
}