-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mdrss_test.go
92 lines (82 loc) · 2.22 KB
/
mdrss_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
84
85
86
87
88
89
90
91
package main
import (
mdrss "github.com/TimoKats/mdrss/lib"
"os/exec"
"testing"
)
func testConfig() mdrss.Config {
var config mdrss.Config
config.Description = "Testing weblog"
config.InputFolder = "test/"
config.OutputFile = "rss.xml"
config.Author = "Testing Test"
config.Link = "[email protected]"
return config
}
func TestFileExists(t *testing.T) {
got := mdrss.FileExists("mdrss.go")
want := true
if got != want {
t.Errorf("got %v, wanted %v", got, want)
}
}
func TestGetArticles(t *testing.T) {
config := testConfig()
articles, _ := mdrss.GetArticles(config)
got := []string{}
want := []string{"another-article.md"}
for _, article := range articles {
got = append(got, article.Filename)
}
if len(got) != len(want) {
t.Errorf("got %v, wanted %v", got, want)
}
}
func TestCreateMarkdown(t *testing.T) {
config := testConfig()
files, _ := mdrss.GetArticles(config)
config.Articles = mdrss.ReadMarkdown(config, files)
got := config.Articles[0].Title
want := "This article has a title."
if got != want {
t.Errorf("got %v, wanted %v", got, want)
}
}
func TestConvertLists(t *testing.T) {
want := "<ul><li>text</li>"
got := mdrss.ConvertMarkdownToRSS(" - text")
if got != want {
t.Errorf("got %v, wanted %v", got, want)
}
}
func TestConvertLinks(t *testing.T) {
want := "<p>Click here for the <a href='https://timokats.xyz'>link</a></p>"
got := mdrss.ConvertMarkdownToRSS("Click here for the [link](https://timokats.xyz)")
if got != want {
t.Errorf("got %v, wanted %v", got, want)
}
}
func TestFakeEnclosures(t *testing.T) {
_, fileSizeErr := mdrss.FileSizeUrl("hello.mp3")
if fileSizeErr == nil {
t.Errorf("Should give Error, but no.")
}
}
func TestBasics(t *testing.T) {
config := testConfig()
articles, _ := mdrss.GetArticles(config)
config.Articles = mdrss.ReadMarkdown(config, articles)
rssXml := mdrss.CreateRSS(config)
rssErr := mdrss.WriteRSS(rssXml, config)
got := mdrss.FileExists("rss.xml")
want := true
if got != want || rssErr != nil {
t.Errorf("got %v, wanted %v", got, want)
} else {
cmd := exec.Command("rm", "rss.xml")
runErr := cmd.Run()
if runErr != nil {
mdrss.Error.Println(runErr)
}
}
}