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: delete generated test data after testing #97

Merged
merged 1 commit into from
Apr 11, 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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
!rendered/
site/rendered/
anna
!anna/
Expand Down
34 changes: 26 additions & 8 deletions pkg/engine/anna_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func TestRenderTags(t *testing.T) {
if err != nil {
t.Errorf("%v", err)
}
if err := os.MkdirAll(TestDirPath+"render_tags/rendered", 0750); err != nil {
t.Errorf("%v", err)
}
e.RenderTags(fileOutPath, templ)

t.Run("render tag.html", func(t *testing.T) {
Expand Down Expand Up @@ -105,14 +108,21 @@ func TestRenderTags(t *testing.T) {
}

if !slices.Equal(got_tech_file, want_tech_file) {
t.Errorf("The expected and generated tech.html tag-subpage can be found in test/engine/render_tags/rendered/tags/")
t.Errorf("The expected and generated tech.html tag-subpage can be found in test/engine/render_tags/rendered/tags/")
}
})
}

if err := os.RemoveAll(TestDirPath + "render_tags/rendered"); err != nil {
t.Errorf("%v", err)
}
}

func TestGenerateMergedJson(t *testing.T) {
t.Run("test json creation from e.Templates", func(t *testing.T) {
if err := os.MkdirAll(TestDirPath+"json_index_test/static", 0750); err != nil {
t.Errorf("%v", err)
}

t.Run("test json creation for the search index", func(t *testing.T) {
e := engine.Engine{
Templates: make(map[template.URL]parser.TemplateData),
TagsMap: make(map[string][]parser.TemplateData),
Expand All @@ -127,14 +137,14 @@ func TestGenerateMergedJson(t *testing.T) {
},
}

e.GenerateJSONIndex(TestDirPath + "merged_data_test")
e.GenerateJSONIndex(TestDirPath + "json_index_test")

got_json, err := os.ReadFile(TestDirPath + "/merged_data_test/static/index.json")
got_json, err := os.ReadFile(TestDirPath + "/json_index_test/static/index.json")
if err != nil {
t.Errorf("%v", err)
}

want_json, err := os.ReadFile(TestDirPath + "/merged_data_test/want_index.json")
want_json, err := os.ReadFile(TestDirPath + "/json_index_test/want_index.json")
if err != nil {
t.Errorf("%v", err)
}
Expand All @@ -143,9 +153,13 @@ func TestGenerateMergedJson(t *testing.T) {
want_json = bytes.TrimSpace(want_json)

if !slices.Equal(got_json, want_json) {
t.Errorf("The expected and generated json can be found in test/layout/")
t.Errorf("The expected and generated json can be found in test/engine/json_index_test")
}
})

if err := os.RemoveAll(TestDirPath + "json_index_test/static"); err != nil {
t.Errorf("%v", err)
}
}

func TestGenerateSitemap(t *testing.T) {
Expand Down Expand Up @@ -205,7 +219,11 @@ func TestGenerateSitemap(t *testing.T) {
})

if strings.Compare(got_sitemap_string, want_sitemap_string) == 0 {
t.Errorf("The expected and generated sitemap can be found in test/layout/sitemap/")
t.Errorf("The expected and generated sitemap can be found in test/engine/sitemap/")
}
})

if err := os.RemoveAll(TestDirPath + "sitemap/got_sitemap.xml"); err != nil {
t.Errorf("%v", err)
}
}
11 changes: 11 additions & 0 deletions pkg/engine/engine_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ func TestRenderUserDefinedPages(t *testing.T) {
parser.TemplateData{
FilenameWithoutExtension: "index",
Body: template.HTML("<h1>Index Page</h1>"),
CompleteURL: "index.html",
}

engine.Templates["posts/hello.md"] = parser.TemplateData{
FilenameWithoutExtension: "hello",
Body: template.HTML("<h1>Hello World</h1>"),
CompleteURL: "posts/hello.html",
}

if err := os.MkdirAll(TestDirPath+"render_user_defined/rendered", 0750); err != nil {
t.Errorf("%v", err)
}

t.Run("render a set of user defined pages", func(t *testing.T) {
Expand All @@ -35,6 +41,7 @@ func TestRenderUserDefinedPages(t *testing.T) {
if err != nil {
t.Errorf("%v", err)
}

engine.RenderUserDefinedPages(TestDirPath+"render_user_defined/", templ)

want_index_file, err := os.ReadFile(TestDirPath + "render_user_defined/want_index.html")
Expand Down Expand Up @@ -65,4 +72,8 @@ func TestRenderUserDefinedPages(t *testing.T) {
t.Errorf("The expected and generated post/hello.html can be found in test/engine/render_user_defined/rendered/posts/")
}
})

if err := os.RemoveAll(TestDirPath + "render_user_defined/rendered"); err != nil {
t.Errorf("%v", err)
}
}
10 changes: 9 additions & 1 deletion pkg/engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
const TestDirPath = "../../test/engine/"

func TestRenderPage(t *testing.T) {
if err := os.MkdirAll(TestDirPath+"render_page/rendered", 0750); err != nil {
t.Errorf("%v", err)
}

t.Run("render a single page while creating a new directory", func(t *testing.T) {
engine := engine.Engine{
Templates: make(map[template.URL]parser.TemplateData),
Expand Down Expand Up @@ -46,7 +50,7 @@ func TestRenderPage(t *testing.T) {
t.Errorf("%v", err)
}

engine.RenderPage(TestDirPath+"engine/render_page/", "posts/got.md", page, templ, "page")
engine.RenderPage(TestDirPath+"render_page/", "posts/got.md", page, templ, "page")

got_file, err := os.ReadFile(TestDirPath + "render_page/rendered/posts/got.html")
if err != nil {
Expand All @@ -62,4 +66,8 @@ func TestRenderPage(t *testing.T) {
t.Errorf("The expected and generated page.html can be found in test/engine/render_page/rendered/")
}
})

if err := os.RemoveAll(TestDirPath + "render_page/rendered"); err != nil {
t.Errorf("%v", err)
}
}
8 changes: 8 additions & 0 deletions pkg/engine/user_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func TestRenderEngineGeneratedFiles(t *testing.T) {
},
}

if err := os.MkdirAll(TestDirPath+"render_engine_generated/rendered", 0750); err != nil {
t.Errorf("%v", err)
}

t.Run("test rendering of post.html", func(t *testing.T) {
templ, err := template.ParseFiles(TestDirPath + "render_engine_generated/posts_template.layout")
if err != nil {
Expand All @@ -69,4 +73,8 @@ func TestRenderEngineGeneratedFiles(t *testing.T) {
t.Errorf("The expected and generated posts.html can be found in test/engine/render_engine_generated/rendered/")
}
})

if err := os.RemoveAll(TestDirPath + "render_engine_generated/rendered"); err != nil {
t.Errorf("%v", err)
}
}
18 changes: 0 additions & 18 deletions test/engine/engine/render_page/rendered/posts/got.html

This file was deleted.

1 change: 0 additions & 1 deletion test/engine/merged_data_test/static/index.json

This file was deleted.

40 changes: 0 additions & 40 deletions test/engine/render_engine_generated/rendered/posts.html

This file was deleted.

18 changes: 0 additions & 18 deletions test/engine/render_page/rendered/posts/got.html

This file was deleted.

13 changes: 0 additions & 13 deletions test/engine/render_tags/rendered/tags.html

This file was deleted.

13 changes: 0 additions & 13 deletions test/engine/render_tags/rendered/tags/blogs.html

This file was deleted.

13 changes: 0 additions & 13 deletions test/engine/render_tags/rendered/tags/tech.html

This file was deleted.

10 changes: 0 additions & 10 deletions test/engine/render_user_defined/rendered/index.html

This file was deleted.

10 changes: 0 additions & 10 deletions test/engine/render_user_defined/rendered/posts/hello.html

This file was deleted.

15 changes: 0 additions & 15 deletions test/engine/sitemap/got_sitemap.xml

This file was deleted.

15 changes: 0 additions & 15 deletions test/engine/want_sitemap.xml

This file was deleted.

Loading