-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathusage_test.go
120 lines (96 loc) · 2.77 KB
/
usage_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
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"flag"
"github.com/skx/rss2email/configfile"
"os"
"testing"
)
// TestUsage just calls the usage-function for each of our handlers,
// and passes some bogus flags to the arguments handler.
func TestUsage(t *testing.T) {
add := addCmd{}
add.Info()
add.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
cron := cronCmd{}
cron.Info()
cron.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
config := configCmd{}
config.Info()
config.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
daemon := daemonCmd{}
daemon.Info()
daemon.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
del := delCmd{}
del.Info()
del.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
export := exportCmd{}
export.Info()
export.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
imprt := importCmd{}
imprt.Info()
imprt.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
list := listCmd{}
list.Info()
list.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
ldt := listDefaultTemplateCmd{}
ldt.Info()
ldt.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
seen := seenCmd{}
seen.Info()
seen.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
unse := unseeCmd{}
unse.Info()
unse.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
vers := versionCmd{}
vers.Info()
vers.Arguments(flag.NewFlagSet("test", flag.ContinueOnError))
}
// TestBrokenConfig is used to test that the commands which assume
// a broken configuration file do so.
func TestBrokenConfig(t *testing.T) {
data := []byte(`# This is bogus, options must follow URLs
- foo:bar`)
tmpfile, err := os.CreateTemp("", "example")
if err != nil {
t.Fatalf("Error creating temporary file")
}
if _, err := tmpfile.Write(data); err != nil {
t.Fatalf("Error writing to config file")
}
if err := tmpfile.Close(); err != nil {
t.Fatalf("Error creating temporary file")
}
// Test the various commands.
a := addCmd{}
a.config = configfile.NewWithPath(tmpfile.Name())
res := a.Execute([]string{})
if res != 1 {
t.Fatalf("expected error with config file")
}
d := delCmd{}
d.config = configfile.NewWithPath(tmpfile.Name())
res = d.Execute([]string{})
if res != 1 {
t.Fatalf("expected error with config file")
}
e := exportCmd{}
e.config = configfile.NewWithPath(tmpfile.Name())
res = e.Execute([]string{})
if res != 1 {
t.Fatalf("expected error with config file")
}
i := importCmd{}
i.config = configfile.NewWithPath(tmpfile.Name())
res = i.Execute([]string{})
if res != 1 {
t.Fatalf("expected error with config file")
}
l := listCmd{}
l.config = configfile.NewWithPath(tmpfile.Name())
res = l.Execute([]string{})
if res != 1 {
t.Fatalf("expected error with config file")
}
// TODO : error-match
os.Remove(tmpfile.Name())
}