-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository_test.go
58 lines (44 loc) · 1 KB
/
repository_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package mongodata
import (
"context"
"encoding/json"
"testing"
)
func TestRepository(t *testing.T) {
t.Skip()
r := NewRepository(nil, bookMapper{})
r.Insert(context.Background(), Book{}, nil)
}
type BookID string
func (b BookID) String() string { return string(b) }
type BookVersion int
func (bv BookVersion) Value() int { return int(bv) }
type Book struct {
id BookID
version int
title string
}
func (b Book) ID() BookID { return b.id }
func (b Book) Version() int { return b.version }
type BookModel struct {
Title string `bson:"title"`
}
type bookMapper struct{}
func (b bookMapper) FromModel(id string, version int, m BookModel) Book {
return Book{
id: BookID(id),
version: version,
title: m.Title,
}
}
func (bookMapper) ToModel(b Book) BookModel {
return BookModel{
Title: b.title,
}
}
func (bookMapper) FromModelEvent(e Event) ([]byte, error) {
return json.Marshal(e)
}
func (bookMapper) ToModelEvent(eType string, data []byte) (Event, bool) {
return nil, false
}