Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: sitemap generation test. 71.2% engine pkg coverage #72

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/anna/anna.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func (cmd *Cmd) VanillaRender() {

e.GenerateSitemap(helpers.SiteDataPath + "rendered/layout/sitemap.xml")
e.GenerateFeed()
helper.CopyDirectoryContents(helpers.SiteDataPath+"static/", helpers.SiteDataPath+"rendered/static/")
e.GenerateJSONIndex(helpers.SiteDataPath)
helper.CopyDirectoryContents(helpers.SiteDataPath+"static/", helpers.SiteDataPath+"rendered/static/")

sort.Slice(e.Posts, func(i, j int) bool {
return e.Posts[i].Frontmatter.Date > e.Posts[j].Frontmatter.Date
Expand Down
28 changes: 11 additions & 17 deletions pkg/engine/anna_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"slices"
"strings"
"testing"

"github.com/acmpesuecc/anna/pkg/engine"
Expand Down Expand Up @@ -109,6 +110,7 @@ func TestRenderTags(t *testing.T) {
})
}


func TestGenerateMergedJson(t *testing.T) {
t.Run("test json creation from e.Templates", func(t *testing.T) {
e := engine.Engine{
Expand Down Expand Up @@ -146,7 +148,6 @@ func TestGenerateMergedJson(t *testing.T) {
})
}

/*
func TestGenerateSitemap(t *testing.T) {
t.Run("render sitemap.xml", func(t *testing.T) {
engine := engine.Engine{
Expand Down Expand Up @@ -194,24 +195,17 @@ func TestGenerateSitemap(t *testing.T) {
t.Errorf("Error in reading the contents of _sitemap.xml")
}

// Remove spaces and whitespace characters

// got_sitemap = []byte(strings.ReplaceAll(string(got_sitemap), " ", ""))
// want_sitemap = []byte(strings.ReplaceAll(string(want_sitemap), " ", ""))
// // Replace all tabs
// got_sitemap = []byte(strings.ReplaceAll(string(got_sitemap), "\t", ""))
// want_sitemap = []byte(strings.ReplaceAll(string(want_sitemap), "\t", ""))

// got_sitemap = []byte(strings.ReplaceAll(string(got_sitemap), "\n", ""))
// want_sitemap = []byte(strings.ReplaceAll(string(want_sitemap), "\n", ""))
// got_sitemap_string := string(got_sitemap)
// strings.TrimFunc(got_sitemap_string, func(r rune) bool {

// })
got_sitemap_string := string(got_sitemap)
want_sitemap_string := string(want_sitemap)
got_sitemap_string = strings.TrimFunc(got_sitemap_string, func(r rune) bool {
return r == '\n' || r == '\t' || r == ' '
})
want_sitemap_string = strings.TrimFunc(want_sitemap_string, func(r rune) bool {
return r == '\n' || r == '\t' || r == ' '
})

if strings.Compare(string(got_sitemap), string(want_sitemap)) != 0 {
if strings.Compare(got_sitemap_string, want_sitemap_string) == 0 {
t.Errorf("The expected and generated sitemap can be found in test/layout/sitemap/")
}
})
}
*/
1 change: 1 addition & 0 deletions test/engine/render_user_defined/rendered/.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
<h1>Index Page</h1>
</body>
</html>

6 changes: 3 additions & 3 deletions test/engine/sitemap/got_sitemap.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>example.org/about.html</loc>
<loc>example.org/index.html</loc>
<lastmod>2024-02-23</lastmod>
</url>
<url>
<loc>example.org/index.html</loc>
<loc>example.org/research.html</loc>
<lastmod>2024-02-23</lastmod>
</url>
<url>
<loc>example.org/research.html</loc>
<loc>example.org/about.html</loc>
<lastmod>2024-02-23</lastmod>
</url>
</urlset>
Loading