owl-blogs/post_test.go

58 lines
1.5 KiB
Go
Raw Normal View History

2022-08-03 14:55:48 +00:00
package owl_test
2022-07-21 17:44:07 +00:00
2022-08-01 17:50:29 +00:00
import (
"path"
"testing"
)
2022-07-21 17:44:07 +00:00
func TestCanGetPostTitle(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost")
result := post.Title()
if result != "testpost" {
t.Error("Wrong Title. Got: " + result)
}
}
2022-08-01 17:50:29 +00:00
func TestMediaDir(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost")
result := post.MediaDir()
if result != path.Join(post.Dir(), "media") {
t.Error("Wrong MediaDir. Got: " + result)
}
}
2022-08-03 17:41:13 +00:00
func TestPostUrlPath(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost")
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())
}
}
func TestPostUrlMediaPath(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost")
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())
}
}
func TestPostUrlMediaPathWithSubDir(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost")
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())
}
}