From 79cb97680db9f225efed034282ddc2438f6fcf9f Mon Sep 17 00:00:00 2001 From: Anirudh Sudhir Date: Thu, 11 Apr 2024 13:01:57 +0530 Subject: [PATCH] test: delete generated test data after testing --- .gitignore | 1 - pkg/engine/anna_engine_test.go | 34 ++++++++++++---- pkg/engine/engine_integration_test.go | 11 +++++ pkg/engine/engine_test.go | 10 ++++- pkg/engine/user_engine_test.go | 8 ++++ .../render_page/rendered/posts/got.html | 18 --------- .../want_index.json | 0 .../engine/merged_data_test/static/index.json | 1 - .../rendered/posts.html | 40 ------------------- .../render_page/rendered/posts/got.html | 18 --------- test/engine/render_tags/rendered/tags.html | 13 ------ .../render_tags/rendered/tags/blogs.html | 13 ------ .../render_tags/rendered/tags/tech.html | 13 ------ .../render_user_defined/rendered/index.html | 10 ----- .../rendered/posts/hello.html | 10 ----- test/engine/sitemap/got_sitemap.xml | 15 ------- test/engine/want_sitemap.xml | 15 ------- 17 files changed, 54 insertions(+), 176 deletions(-) delete mode 100644 test/engine/engine/render_page/rendered/posts/got.html rename test/engine/{merged_data_test => json_index_test}/want_index.json (100%) delete mode 100644 test/engine/merged_data_test/static/index.json delete mode 100644 test/engine/render_engine_generated/rendered/posts.html delete mode 100644 test/engine/render_page/rendered/posts/got.html delete mode 100644 test/engine/render_tags/rendered/tags.html delete mode 100644 test/engine/render_tags/rendered/tags/blogs.html delete mode 100644 test/engine/render_tags/rendered/tags/tech.html delete mode 100644 test/engine/render_user_defined/rendered/index.html delete mode 100644 test/engine/render_user_defined/rendered/posts/hello.html delete mode 100644 test/engine/sitemap/got_sitemap.xml delete mode 100644 test/engine/want_sitemap.xml diff --git a/.gitignore b/.gitignore index 211b43d..f1febea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -!rendered/ site/rendered/ anna !anna/ diff --git a/pkg/engine/anna_engine_test.go b/pkg/engine/anna_engine_test.go index 985ccd0..38ada32 100644 --- a/pkg/engine/anna_engine_test.go +++ b/pkg/engine/anna_engine_test.go @@ -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) { @@ -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), @@ -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) } @@ -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) { @@ -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) + } } diff --git a/pkg/engine/engine_integration_test.go b/pkg/engine/engine_integration_test.go index 906b7fb..678f379 100644 --- a/pkg/engine/engine_integration_test.go +++ b/pkg/engine/engine_integration_test.go @@ -22,11 +22,17 @@ func TestRenderUserDefinedPages(t *testing.T) { parser.TemplateData{ FilenameWithoutExtension: "index", Body: template.HTML("

Index Page

"), + CompleteURL: "index.html", } engine.Templates["posts/hello.md"] = parser.TemplateData{ FilenameWithoutExtension: "hello", Body: template.HTML("

Hello World

"), + 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) { @@ -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") @@ -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) + } } diff --git a/pkg/engine/engine_test.go b/pkg/engine/engine_test.go index f39cf89..f54ba25 100644 --- a/pkg/engine/engine_test.go +++ b/pkg/engine/engine_test.go @@ -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), @@ -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 { @@ -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) + } } diff --git a/pkg/engine/user_engine_test.go b/pkg/engine/user_engine_test.go index 3c046cc..1116923 100644 --- a/pkg/engine/user_engine_test.go +++ b/pkg/engine/user_engine_test.go @@ -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 { @@ -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) + } } diff --git a/test/engine/engine/render_page/rendered/posts/got.html b/test/engine/engine/render_page/rendered/posts/got.html deleted file mode 100644 index 6cfcd99..0000000 --- a/test/engine/engine/render_page/rendered/posts/got.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - -
- -
-blog -
- - - -
-

Hello World

- - diff --git a/test/engine/merged_data_test/want_index.json b/test/engine/json_index_test/want_index.json similarity index 100% rename from test/engine/merged_data_test/want_index.json rename to test/engine/json_index_test/want_index.json diff --git a/test/engine/merged_data_test/static/index.json b/test/engine/merged_data_test/static/index.json deleted file mode 100644 index b9e300f..0000000 --- a/test/engine/merged_data_test/static/index.json +++ /dev/null @@ -1 +0,0 @@ -{"docs.md":{"CompleteURL":"docs.html","FilenameWithoutExtension":"docs","Frontmatter":{"Title":"Anna Documentation","Date":"","Draft":false,"JSFiles":null,"Type":"","Description":"","PreviewImage":"","Tags":null,"Authors":null},"Tags":null}} \ No newline at end of file diff --git a/test/engine/render_engine_generated/rendered/posts.html b/test/engine/render_engine_generated/rendered/posts.html deleted file mode 100644 index 9a5b556..0000000 --- a/test/engine/render_engine_generated/rendered/posts.html +++ /dev/null @@ -1,40 +0,0 @@ - - - -
- -
- - diff --git a/test/engine/render_page/rendered/posts/got.html b/test/engine/render_page/rendered/posts/got.html deleted file mode 100644 index 6cfcd99..0000000 --- a/test/engine/render_page/rendered/posts/got.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - -
- -
-blog -
- - - -
-

Hello World

- - diff --git a/test/engine/render_tags/rendered/tags.html b/test/engine/render_tags/rendered/tags.html deleted file mode 100644 index 1c73adc..0000000 --- a/test/engine/render_tags/rendered/tags.html +++ /dev/null @@ -1,13 +0,0 @@ - - -
-
- -blogs - -tech - -
-
- - diff --git a/test/engine/render_tags/rendered/tags/blogs.html b/test/engine/render_tags/rendered/tags/blogs.html deleted file mode 100644 index 3d48ac2..0000000 --- a/test/engine/render_tags/rendered/tags/blogs.html +++ /dev/null @@ -1,13 +0,0 @@ - - -
-
- -file1 - -file2 - -
-
- - diff --git a/test/engine/render_tags/rendered/tags/tech.html b/test/engine/render_tags/rendered/tags/tech.html deleted file mode 100644 index 88497f7..0000000 --- a/test/engine/render_tags/rendered/tags/tech.html +++ /dev/null @@ -1,13 +0,0 @@ - - -
-
- -file2 - -file3 - -
-
- - diff --git a/test/engine/render_user_defined/rendered/index.html b/test/engine/render_user_defined/rendered/index.html deleted file mode 100644 index c3dcf98..0000000 --- a/test/engine/render_user_defined/rendered/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - -
- -
-

Index Page

- - diff --git a/test/engine/render_user_defined/rendered/posts/hello.html b/test/engine/render_user_defined/rendered/posts/hello.html deleted file mode 100644 index d4fc935..0000000 --- a/test/engine/render_user_defined/rendered/posts/hello.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - -
- -
-

Hello World

- - diff --git a/test/engine/sitemap/got_sitemap.xml b/test/engine/sitemap/got_sitemap.xml deleted file mode 100644 index dc94b5b..0000000 --- a/test/engine/sitemap/got_sitemap.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - example.org/index.html - 2024-02-23 - - - example.org/research.html - 2024-02-23 - - - example.org/about.html - 2024-02-23 - - diff --git a/test/engine/want_sitemap.xml b/test/engine/want_sitemap.xml deleted file mode 100644 index 5578525..0000000 --- a/test/engine/want_sitemap.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - example.org/about.html - 2024-02-23 - - - example.org/index.html - 2024-02-23 - - - example.org/research.html - 2024-02-23 - -