-
Notifications
You must be signed in to change notification settings - Fork 2
/
gonetact_test.go
99 lines (90 loc) · 2.67 KB
/
gonetact_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
package main
import (
"testing"
"os/user"
"fmt"
)
func Test_readCommandLine_1(t *testing.T) {
// Test the no_browser flag
usr, _ := user.Current()
rc_dir := fmt.Sprintf("%s/.gonetact", usr.HomeDir)
client_id := fmt.Sprintf("%s/client.json", rc_dir)
cache_file := fmt.Sprintf("%s/cache.json", rc_dir)
input_argv := []string{"gonetacts", "--no-browser"}
expected_output := CmdLineOpts {
client_id : client_id,
cache_file : cache_file,
no_browser : true,
username: "",
query: "",
}
parsed := readCommandLine(input_argv)
if expected_output != *parsed {
fmt.Println(expected_output)
fmt.Println(*parsed)
t.Error("The returned flags do not look like the flags we specified.")
}
}
func Test_readCommandLine_2(t *testing.T) {
// Test the query argument
usr, _ := user.Current()
rc_dir := fmt.Sprintf("%s/.gonetact", usr.HomeDir)
client_id := fmt.Sprintf("%s/client.json", rc_dir)
cache_file := fmt.Sprintf("%s/cache.json", rc_dir)
input_argv := []string{"gonetacts", "--query=foo"}
expected_output := CmdLineOpts {
client_id : client_id,
cache_file : cache_file,
no_browser : false,
username: "",
query: "foo",
}
parsed := readCommandLine(input_argv)
if expected_output != *parsed {
fmt.Println(expected_output)
fmt.Println(*parsed)
t.Error("The returned flags do not look like the flags we specified.")
}
}
func Test_readCommandLine_3(t *testing.T) {
// Test the client-id argument
usr, _ := user.Current()
rc_dir := fmt.Sprintf("%s/.gonetact", usr.HomeDir)
client_id := "/something/foo/client_id.json"
cache_file := fmt.Sprintf("%s/cache.json", rc_dir)
input_argv := []string{"gonetacts", fmt.Sprintf("--client-id=%s", client_id)}
expected_output := CmdLineOpts {
client_id : client_id,
cache_file : cache_file,
no_browser : false,
username: "",
query: "",
}
parsed := readCommandLine(input_argv)
if expected_output != *parsed {
fmt.Println(expected_output)
fmt.Println(*parsed)
t.Error("The returned flags do not look like the flags we specified.")
}
}
func Test_readCommandLine_4(t *testing.T) {
// Test the cache-file argument
usr, _ := user.Current()
rc_dir := fmt.Sprintf("%s/.gonetact", usr.HomeDir)
client_id := fmt.Sprintf("%s/client.json", rc_dir)
cache_file := "/something/foo/client_id.json"
input_argv := []string{"gonetacts", fmt.Sprintf("--cache=%s", cache_file)}
expected_output := CmdLineOpts {
client_id : client_id,
cache_file : cache_file,
no_browser : false,
username: "",
query: "",
}
parsed := readCommandLine(input_argv)
if expected_output != *parsed {
fmt.Println(expected_output)
fmt.Println(*parsed)
t.Error("The cache-file argument didn't come through per the args we specified.")
}
}