-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdel_cmd_test.go
59 lines (48 loc) · 1.2 KB
/
del_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
package main
import (
"os"
"testing"
"github.com/skx/rss2email/configfile"
)
func TestDel(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")
}
del := delCmd{}
del.Arguments(nil) // only for coverage
config := configfile.NewWithPath(tmpfile.Name())
del.config = config
// Delete an entry
del.Execute([]string{"https://example.net/"})
// Open the file and confirm only one entry.
x := configfile.NewWithPath(tmpfile.Name())
entries, err := x.Parse()
if err != nil {
t.Fatalf("Error parsing written file")
}
if len(entries) != 1 {
t.Fatalf("Expected only one entry")
}
if entries[0].URL != "https://example.org/" {
t.Fatalf("Wrong item deleted")
}
if len(entries[0].Options) != 0 {
t.Fatalf("We have orphaned parameters")
}
os.Remove(tmpfile.Name())
}