-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathexport_cmd_test.go
67 lines (55 loc) · 1.24 KB
/
export_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
package main
import (
"bytes"
"os"
"strings"
"testing"
"github.com/skx/rss2email/configfile"
)
func TestExport(t *testing.T) {
// Replace the STDIO handle
bak := out
out = &bytes.Buffer{}
defer func() { out = bak }()
// Create a simple configuration file
content := `# Comment here
https://example.org/
https://example.net/
- foo: bar
`
data := []byte(content)
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")
}
// Create an instance of the command, and setup the config file
ex := exportCmd{}
ex.Arguments(nil)
config := configfile.NewWithPath(tmpfile.Name())
ex.config = config
// Run the export
ex.Execute([]string{})
//
// Look for some lines in the output
//
expected := []string{
"Feed Export",
"xmlUrl=\"https://example.org/\"",
"</opml>",
}
// 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")
}
}
// Cleanup
os.Remove(tmpfile.Name())
}