blogposts: add the first test

This commit is contained in:
vinchent 2024-09-23 23:09:10 +02:00
parent ef646bf98e
commit 048e6cccac
3 changed files with 39 additions and 0 deletions

12
blogposts/blogposts.go Normal file
View File

@ -0,0 +1,12 @@
package blogposts
import "io/fs"
type Post struct {
Title, Description, Body string
Tags []string
}
func NewPostsFromFS(fs fs.FS) []Post {
return []Post{{}, {}}
}

View File

@ -0,0 +1,20 @@
package blogposts
import (
"testing"
"testing/fstest"
)
// NOTE: This should be a black box test outside blogposts package.
func TestNewBlogPosts(t *testing.T) {
fs := fstest.MapFS{
"hello world.md": {Data: []byte("hi")},
"hello-world2.md": {Data: []byte("hola")},
}
posts := NewPostsFromFS(fs)
if len(posts) != len(fs) {
t.Errorf("got %d posts, wanted %d posts", len(posts), len(fs))
}
}

7
blogposts/hello_world.md Normal file
View File

@ -0,0 +1,7 @@
Title: Hello, TDD world!
Description: First post on our wonderful blog
Tags: tdd, go
---
Hello world!
The body of posts starts after the `---`