-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontent_test.go
148 lines (124 loc) · 2.74 KB
/
content_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main
import (
"testing"
"time"
)
const ArticleContent string = `---
title: Test Article
author: Coconut Test
image:
tags:
- article
- test
- post
date: Jan 5 2015 13:50
---
This is an article test
'""<>[]{}&'`
const PageContent string = `---
title: Test Page
---
This is a test Page!`
//The article we get is written out in TestMain
//The tests for Article related functions all
//get that article and test based upon it
func getArticle(t *testing.T, articleName string) *Article {
article, err := GetArticle(articleName)
if err != nil {
t.Fatal("Existing article not found", err)
}
return article
}
func TestGetArticleWithExistingArticle(t *testing.T) {
getArticle(t, "test-article.md")
}
func TestGetArticleWithMissingArticle(t *testing.T) {
article, err := GetArticle("missing-article.md")
if err == nil && article != nil {
t.Fail()
}
}
func TestGetArticleMetadata(t *testing.T) {
article := getArticle(t, "test-article.md")
if article.Title != "Test Article" {
t.Fail()
}
if article.Author != "Coconut Test" {
t.Fail()
}
if article.Tags[0] != "article" || article.Tags[1] != "test" || article.Tags[2] != "post" {
t.Fail()
}
if article.Image != "" && article.HaveImage {
t.Fail()
}
time, err := time.Parse(DateFormat, "Jan 5 2015 13:50")
if err != nil {
t.Fatal("Parsing Date failed, this is a broken test.", err)
}
if !article.Time.Equal(time) {
t.Fail()
}
}
func TestGetArticleBody(t *testing.T) {
article := getArticle(t, "test-article.md")
if article.Body == "" {
t.Fail()
}
}
func TestArticleHasTag(t *testing.T) {
article := getArticle(t, "test-article.md")
if !article.HasTag("article") {
t.Fail()
}
if !article.HasTag("test") {
t.Fail()
}
if !article.HasTag("post") {
t.Fail()
}
}
func TestArticleDate(t *testing.T) {
article := getArticle(t, "test-article.md")
if article.Date() != "Jan 5 2015 13:50" {
t.Fail()
}
}
func TestGetArticles(t *testing.T) {
articles := GetArticles(func(a *Article) bool { return true })
if len(articles) != 2 {
t.Fail()
}
}
//Test pages
func getPage(t *testing.T, pageName string) *Page {
page, err := GetPage(pageName)
if err != nil || page == nil {
t.Fatal("Error getting existing page:", err)
}
return page
}
func TestGetPageWithExistingPage(t *testing.T) {
page, err := GetPage("pages/test-page.md")
if err != nil || page == nil {
t.Fail()
}
}
func TestGetPageWithMissingPage(t *testing.T) {
page, err := GetPage("pages/missing-page.md")
if err == nil || page != nil {
t.Fail()
}
}
func TestGetPageMetadata(t *testing.T) {
page := getPage(t, "pages/test-page.md")
if page.Title != "Test Page" {
t.Fail()
}
}
func TestGetPageBody(t *testing.T) {
page := getPage(t, "pages/test-page.md")
if page.Body == "" {
t.Fail()
}
}