creating media dir

This commit is contained in:
Niko Abeler 2022-08-01 19:50:29 +02:00
parent 03a27f890c
commit 9d14e1a8fc
4 changed files with 30 additions and 1 deletions

View File

@ -21,6 +21,10 @@ func (post Post) Dir() string {
return path.Join(post.user.Dir(), "public", post.id) return path.Join(post.user.Dir(), "public", post.id)
} }
func (post Post) MediaDir() string {
return path.Join(post.Dir(), "media")
}
func (post Post) UrlPath() string { func (post Post) UrlPath() string {
return post.user.Path() + "/" + post.id return post.user.Path() + "/" + post.id
} }

View File

@ -1,6 +1,9 @@
package kiss_test package kiss_test
import "testing" import (
"path"
"testing"
)
func TestCanGetPostTitle(t *testing.T) { func TestCanGetPostTitle(t *testing.T) {
user := getTestUser() user := getTestUser()
@ -10,3 +13,12 @@ func TestCanGetPostTitle(t *testing.T) {
t.Error("Wrong Title. Got: " + result) t.Error("Wrong Title. Got: " + result)
} }
} }
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)
}
}

View File

@ -94,6 +94,8 @@ func (user User) CreateNewPost(title string) (Post, error) {
// create post file // create post file
os.Mkdir(post_dir, 0755) os.Mkdir(post_dir, 0755)
os.WriteFile(post.ContentFile(), []byte(initial_content), 0644) os.WriteFile(post.ContentFile(), []byte(initial_content), 0644)
// create media dir
os.Mkdir(post.MediaDir(), 0755)
return post, nil return post, nil
} }

View File

@ -24,6 +24,17 @@ func TestCreateNewPostCreatesEntryInPublic(t *testing.T) {
} }
} }
func TestCreateNewPostCreatesMediaDir(t *testing.T) {
// Create a new user
repo, _ := kiss.CreateRepository(testRepoName())
user, _ := repo.CreateUser(randomUserName())
// Create a new post
post, _ := user.CreateNewPost("testpost")
if _, err := os.Stat(post.MediaDir()); os.IsNotExist(err) {
t.Error("Media directory not created")
}
}
func TestCreateNewPostMultipleCalls(t *testing.T) { func TestCreateNewPostMultipleCalls(t *testing.T) {
// Create a new user // Create a new user
repo, _ := kiss.CreateRepository(testRepoName()) repo, _ := kiss.CreateRepository(testRepoName())