-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathimport_cmd_test.go
79 lines (69 loc) · 1.82 KB
/
import_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
package main
import (
"os"
"testing"
"github.com/skx/rss2email/configfile"
)
func TestImport(t *testing.T) {
// 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 OPML file to use as input
opml, err := os.CreateTemp("", "opml")
if err != nil {
t.Fatalf("Error creating temporary file for OMPL input")
}
d1 := []byte(`
<?xml version="1.0" encoding="utf-8"?>
<opml version="1.0">
<head>
<title>Feed Value</title>
</head>
<body>
<outline xmlUrl="http://floooh.github.io/feed.xml"/>
<outline xmlUrl="http://feeds.feedburner.com/24ways"/>
<outline xmlUrl="http://feeds.feedburner.com/2ality"/>
<outline xmlUrl="http://feeds.feedburner.com/AJAXMagazine"/>
<outline xmlUrl="http://alexsexton.com/?feed=rss2"/>
<outline xmlUrl="http://www.broken-links.com/feed/"/>
<outline xmlUrl="http://www.wait-till-i.com/feed/"/>
</body>
</opml>
`)
err = os.WriteFile(opml.Name(), d1, 0644)
if err != nil {
t.Fatalf("failed to write OPML file")
}
// Create an instance of the command, and setup the config file
im := importCmd{}
im.Arguments(nil)
config := configfile.NewWithPath(tmpfile.Name())
im.config = config
// Run the import
im.Execute([]string{opml.Name()})
// Look for the new entries in the feed.
entries, err2 := config.Parse()
if err2 != nil {
t.Errorf("error parsing the (updated) config file")
}
if len(entries) != 9 {
t.Fatalf("found %d entries", len(entries))
}
// Cleanup
os.Remove(tmpfile.Name())
os.Remove(opml.Name())
}