-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_controller_test.go
44 lines (40 loc) · 1.05 KB
/
post_controller_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"github.com/JoeSelvik/hdm-service/models"
"testing"
)
// TestPostController_Create tests Create and Read for posts.
//
// todo: expand once all of the post functions are implemented
func TestPostController_Create(t *testing.T) {
config := NewConfig()
db, err := models.OpenDB(config.DbTestPath)
if err != nil {
t.Fatal("Could not open test db")
}
pc := &PostController{db: db}
originalPosts, postResources := testPosts()
// create the post resource
pids, aerr := pc.Create(postResources)
if aerr != nil {
t.Fatal("Should not error when creating post")
}
if len(pids) != 1 {
t.Fatal("Should only get back a single id")
}
// read all posts
resources, aerr := pc.ReadCollection()
if aerr != nil {
t.Fatal("Unable to read collection of posts")
}
var lookup *models.Post
for _, c := range resources {
if c.(*models.Post).AuthorFbId == originalPosts[0].AuthorFbId {
lookup = c.(*models.Post)
break
}
}
if lookup.AuthorFbId != originalPosts[0].AuthorFbId {
t.Fatal("Unable to find post in ReadCollection")
}
}