-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathconfig_cmd_test.go
87 lines (71 loc) · 1.53 KB
/
config_cmd_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
package main
import (
"bytes"
"flag"
"os"
"strings"
"testing"
"github.com/skx/rss2email/configfile"
)
func TestConfig(t *testing.T) {
bak := out
out = &bytes.Buffer{}
defer func() { out = bak }()
s := configCmd{}
//
// Call the handler.
//
s.Execute([]string{})
//
// Look for some lines in the output
//
expected := []string{
"release 3.x",
"RSS2Email is a simple",
}
// The text written to stdout
output := out.(*bytes.Buffer).String()
for _, txt := range expected {
if !strings.Contains(output, txt) {
t.Fatalf("Failed to find expected output")
}
}
}
// TestMissingConfig ensures we see a warning if the configuration
// file is not present.
func TestMissingConfig(t *testing.T) {
// Create a temporary file, so we get a name of something
// that doesn't exist
tmpfile, err := os.CreateTemp("", "example")
if err != nil {
t.Fatalf("failed to create temporary file")
}
os.Remove(tmpfile.Name())
//
// Setup a configuration-file, which doesn't exist.
//
s := configCmd{}
flags := flag.NewFlagSet("test", flag.ContinueOnError)
s.Arguments(flags)
config := configfile.NewWithPath(tmpfile.Name())
s.config = config
// Get the documentation
_, doc := s.Info()
//
// Look for some lines in the output
//
expected := []string{
tmpfile.Name(),
// known configuration options
"include ",
"include-title",
"exclude ",
"exclude-title",
"exclude-older",
}
for _, txt := range expected {
if !strings.Contains(doc, txt) {
t.Fatalf("Failed to find expected output: %s", txt)
}
}
}