blogposts: add the first test
This commit is contained in:
parent
ef646bf98e
commit
048e6cccac
12
blogposts/blogposts.go
Normal file
12
blogposts/blogposts.go
Normal 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{{}, {}}
|
||||
}
|
20
blogposts/blogposts_test.go
Normal file
20
blogposts/blogposts_test.go
Normal 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
7
blogposts/hello_world.md
Normal 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 `---`
|
Loading…
Reference in New Issue
Block a user