From 4aef1ca2eeb6a55b75fdd8c6af2c075046339ee1 Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Wed, 2 Nov 2022 22:12:58 +0100 Subject: [PATCH] WIP more cleaning up tests --- post_test.go | 42 ++++++++------------------------------ priv/assertions/asserts.go | 21 +++++++++++++++++++ user_test.go | 13 ++++-------- 3 files changed, 33 insertions(+), 43 deletions(-) diff --git a/post_test.go b/post_test.go index 98ebf3e..1df2ebc 100644 --- a/post_test.go +++ b/post_test.go @@ -6,7 +6,6 @@ import ( "os" "path" "strconv" - "strings" "sync" "testing" "time" @@ -16,62 +15,42 @@ func TestCanGetPostTitle(t *testing.T) { user := getTestUser() post, _ := user.CreateNewPost("testpost", false) result := post.Title() - if result != "testpost" { - t.Error("Wrong Title. Got: " + result) - } + assertions.AssertEqual(t, result, "testpost") } func TestMediaDir(t *testing.T) { user := getTestUser() post, _ := user.CreateNewPost("testpost", false) result := post.MediaDir() - if result != path.Join(post.Dir(), "media") { - t.Error("Wrong MediaDir. Got: " + result) - } + assertions.AssertEqual(t, result, path.Join(post.Dir(), "media")) } func TestPostUrlPath(t *testing.T) { user := getTestUser() post, _ := user.CreateNewPost("testpost", false) expected := "/user/" + user.Name() + "/posts/" + post.Id() + "/" - if !(post.UrlPath() == expected) { - t.Error("Wrong url path") - t.Error("Expected: " + expected) - t.Error(" Got: " + post.UrlPath()) - } + assertions.AssertEqual(t, post.UrlPath(), expected) } func TestPostFullUrl(t *testing.T) { user := getTestUser() post, _ := user.CreateNewPost("testpost", false) expected := "http://localhost:8080/user/" + user.Name() + "/posts/" + post.Id() + "/" - if !(post.FullUrl() == expected) { - t.Error("Wrong url path") - t.Error("Expected: " + expected) - t.Error(" Got: " + post.FullUrl()) - } + assertions.AssertEqual(t, post.FullUrl(), expected) } func TestPostUrlMediaPath(t *testing.T) { user := getTestUser() post, _ := user.CreateNewPost("testpost", false) expected := "/user/" + user.Name() + "/posts/" + post.Id() + "/media/data.png" - if !(post.UrlMediaPath("data.png") == expected) { - t.Error("Wrong url path") - t.Error("Expected: " + expected) - t.Error(" Got: " + post.UrlPath()) - } + assertions.AssertEqual(t, post.UrlMediaPath("data.png"), expected) } func TestPostUrlMediaPathWithSubDir(t *testing.T) { user := getTestUser() post, _ := user.CreateNewPost("testpost", false) expected := "/user/" + user.Name() + "/posts/" + post.Id() + "/media/foo/data.png" - if !(post.UrlMediaPath("foo/data.png") == expected) { - t.Error("Wrong url path") - t.Error("Expected: " + expected) - t.Error(" Got: " + post.UrlPath()) - } + assertions.AssertEqual(t, post.UrlMediaPath("foo/data.png"), expected) } func TestDraftInMetaData(t *testing.T) { @@ -85,10 +64,7 @@ func TestDraftInMetaData(t *testing.T) { content += "Write your post here.\n" os.WriteFile(post.ContentFile(), []byte(content), 0644) meta := post.Meta() - if !meta.Draft { - t.Error("Draft should be true") - } - + assertions.AssertEqual(t, meta.Draft, true) } func TestNoRawHTMLIfDisallowedByRepo(t *testing.T) { @@ -104,9 +80,7 @@ func TestNoRawHTMLIfDisallowedByRepo(t *testing.T) { os.WriteFile(post.ContentFile(), []byte(content), 0644) html := post.RenderedContent() html_str := html.String() - if strings.Contains(html_str, "