-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
blog_comment_test.go
62 lines (49 loc) · 1.47 KB
/
blog_comment_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
package ephemeris
import (
"strings"
"testing"
)
// Test reading a file that doesn't exist.
func TestMissing(t *testing.T) {
_, err := NewBlogComment("_test/file/is/not/present")
if err == nil {
t.Errorf("expected error reading a missing file, got none")
}
}
// Test reading a valid blog-comment
func TestValid(t *testing.T) {
b, err := NewBlogComment("_test/blog_comment/valid.html.12345")
if err != nil {
t.Errorf("unexpected error %s", err.Error())
}
if !strings.Contains(b.Body, "example.com") {
t.Errorf("comment-body didn't contain our link")
}
if b.Link != "http://example.net" {
t.Errorf("link doesn't contain a http-prefix: %s", b.Link)
}
}
// Test reading a badly-named comment-file
//
// Blog-posts should be "${name}.html.${ctime}".
func TestBadNaming(t *testing.T) {
_, err := NewBlogComment("_test/blog_comment/invalid.html.html")
if err == nil {
t.Errorf("received no error, but wanted one")
}
if !strings.Contains(err.Error(), "parsing") {
t.Errorf("the error we got didn't seem to refer to parsing 'html' as an integer")
}
}
// Test reading a badly-formed file.
//
// The header should be "key:val" or "key = val". Anything else is bogus.
func TestBadHeader(t *testing.T) {
_, err := NewBlogComment("_test/blog_comment/invalid.html.12345")
if err == nil {
t.Errorf("received no error, but wanted one")
}
if !strings.Contains(err.Error(), "header") {
t.Errorf("the error we got didn't seem to refer to parsing 'html' as an integer")
}
}