@@ -3,7 +3,6 @@ package blawg
3
3
import (
4
4
"bytes"
5
5
"html/template"
6
- "io/ioutil"
7
6
"os"
8
7
"testing"
9
8
"time"
@@ -53,7 +52,7 @@ func TestMakePosts(t *testing.T) {
53
52
for _ , post := range posts {
54
53
expectedFile := testSiteDirectory + "/posts/" + post .Path () + "index.html"
55
54
assert .FileExists (expectedFile )
56
- contents , _ := ioutil .ReadFile (expectedFile )
55
+ contents , _ := os .ReadFile (expectedFile )
57
56
assert .StringContains (string (contents ), string (post .Title ))
58
57
}
59
58
@@ -62,20 +61,26 @@ func TestMakePosts(t *testing.T) {
62
61
63
62
func TestPostsIndex (t * testing.T ) {
64
63
assert := NewAssertions (t )
65
- postOne := testPost ("Abba" , "First Post Body" , 1979 , 12 , 5 )
66
- postTwo := testPost ("Second Post" , "Second Post Body" , 1989 , 12 , 5 )
64
+ post := testPost ("Abba" , "First Post Body" , 1979 , 12 , 5 )
65
+ unpublishedPost := testPost ("Unpublished Post" , "Second Post Body" , 1989 , 12 , 5 )
66
+ unpublishedPost .Published = false
67
+
67
68
posts := Posts {
68
- postOne ,
69
- postTwo ,
69
+ post ,
70
+ unpublishedPost ,
70
71
}
71
72
72
- indexTemplate , err := template .New ("index" ).Parse (`<p> {{range .}}{{.Title}}{{end}}</p>"` )
73
+ indexTemplate , err := template .New ("index" ).Parse (" {{range .}}<p> {{.Title}}</p> \n {{end}}" )
73
74
assert .NotError (err )
74
75
75
76
err = makePostIndex (testSiteDirectory , & posts , indexTemplate )
76
77
assert .NotError (err )
77
78
78
79
assert .FileExists (testSiteDirectory + "/posts/index.html" )
80
+ fileContents , _ := os .ReadFile (testSiteDirectory + "/posts/index.html" )
81
+
82
+ assert .StringContains (string (fileContents ), string (post .Title ))
83
+ assert .StringDoesNotContain (string (fileContents ), string (unpublishedPost .Title ))
79
84
}
80
85
81
86
func TestBuildPostPath (t * testing.T ) {
@@ -136,8 +141,8 @@ func TestNotSavingUnpublishedPost(t *testing.T) {
136
141
err = makePost (testSiteDirectory , & post , nil , stubTemplate ())
137
142
assert .NotError (err )
138
143
139
- unexpectedFile := testSiteDirectory + "/posts/" + post .Path () + "index.html"
140
- assert .FileDoesntExist ( unexpectedFile )
144
+ unpublishedFile := testSiteDirectory + "/posts/" + post .Path () + "index.html"
145
+ assert .FileExists ( unpublishedFile )
141
146
142
147
tearDownTestSite (t )
143
148
}
0 commit comments