creating media dir
This commit is contained in:
parent
03a27f890c
commit
9d14e1a8fc
4
post.go
4
post.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
14
post_test.go
14
post_test.go
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
2
user.go
2
user.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
user_test.go
11
user_test.go
|
@ -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())
|
||||||
|
|
Loading…
Reference in New Issue