-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
83 lines (72 loc) · 1.66 KB
/
main_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
package main
import (
"fmt"
"github.com/joho/godotenv"
"github.com/mmcdole/gofeed"
"os"
"testing"
)
var exampleFeed = Feed{
Name: "Example",
Url: "https://example.com/feed.xml",
Interval: 60,
Filters: make([]struct {
Include FeedFilter
Exclude FeedFilter
}, 0),
Notifiers: make([]map[string]map[string]string, 0),
}
var exampleFilter = struct {
Include FeedFilter
Exclude FeedFilter
}{
Include: FeedFilter{
Element: "item",
Matches: ".*",
},
}
var exampleMatchItem = &gofeed.Item{
Title: "Example Title",
Description: "Example Description",
Link: "https://example.com/",
Links: []string{
"https://example.com/",
},
Content: "Example Content",
Updated: "Example Updated",
}
func setupTests() {
godotenv.Load(".env")
}
func TestLoadPlugins(t *testing.T) {
plugins, err := loadPlugins()
if err != nil {
t.Error("Error loading plugins: ", err)
}
if len(plugins) == 0 {
t.Error("No plugins loaded")
}
}
func TestSendFeedNotifications(t *testing.T) {
setupTests()
var exampleNotifier = map[string]map[string]string{
"gotify": {
"url": os.Getenv("GOTIFY_URL"),
"token": os.Getenv("GOTIFY_TOKEN"),
},
}
exampleFeed.Filters = append(exampleFeed.Filters, exampleFilter)
exampleFeed.Notifiers = append(exampleFeed.Notifiers, exampleNotifier)
fmt.Println("TEST: Loading plugins")
plugins, err := loadPlugins()
if err != nil {
t.Error("Error loading plugins: ", err)
}
status, err := sendFeedNotifications(exampleFeed, exampleMatchItem, plugins)
if err != nil {
t.Errorf("Error sending notification, Error: %s", err)
}
if status != "ok" {
t.Errorf("Error sending notification, Status: %s", status)
}
}