Skip to content

Commit

Permalink
feat(fs): add file reader
Browse files Browse the repository at this point in the history
  • Loading branch information
JRasmusBm committed Jun 30, 2022
1 parent 08f3d7c commit 5b78018
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions blogposts/blogposts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package blogposts

import "testing/fstest"

type Post struct {
}

func NewPostsFromFS(filesystem fstest.MapFS) []Post {
return []Post{{}, {}}
}
25 changes: 25 additions & 0 deletions blogposts/blogposts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package blogposts_test

import (
blogposts "github.com/jrasmusbm/learn-go-with-tests/reading-files"

"testing"
"testing/fstest"
)

func TestNewBlogPosts(t *testing.T) {
t.Run("Creates new blog posts", func(t *testing.T) {
fs := fstest.MapFS{
"hello world.md": {Data: []byte("hi")},
"hello-world2.md": {Data: []byte("hola")},
}

got := len(blogposts.NewPostsFromFS(fs))
want := len(fs)

if got != want {
t.Errorf("got %v posts, want %v posts", got, want)
}
})

}
3 changes: 3 additions & 0 deletions blogposts/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/jrasmusbm/learn-go-with-tests/reading-files

go 1.18

0 comments on commit 5b78018

Please sign in to comment.