-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathadd_cmd_test.go
60 lines (48 loc) · 1.16 KB
/
add_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
package main
import (
"os"
"testing"
"github.com/skx/rss2email/configfile"
)
func TestAdd(t *testing.T) {
// Create an instance of the command, and setup a default
// 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")
}
add := addCmd{}
add.Arguments(nil)
config := configfile.NewWithPath(tmpfile.Name())
add.config = config
// Add an entry
add.Execute([]string{"https://blog.steve.fi/index.rss"})
// Open the file and confirm it has the content we expect
x := configfile.NewWithPath(tmpfile.Name())
entries, err := x.Parse()
if err != nil {
t.Fatalf("Error parsing written file")
}
found := false
for _, entry := range entries {
if entry.URL == "https://blog.steve.fi/index.rss" {
found = true
}
}
if !found {
t.Fatalf("Adding the entry failed")
}
os.Remove(tmpfile.Name())
}