-
Notifications
You must be signed in to change notification settings - Fork 1
/
model_test.go
60 lines (53 loc) · 1.3 KB
/
model_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
59
60
package qbin
import (
"testing"
"github.com/qbin-io/backend"
)
func connect() {
if !qbin.IsConnected() {
err := qbin.Connect("root:@tcp(localhost)/qbin")
if err != nil {
panic(err)
}
}
}
func TestDocumentStorage(t *testing.T) {
connect()
exp, err := qbin.ParseExpiration("15m")
if err != nil {
t.Error(err)
t.FailNow()
}
doc := qbin.Document{
Content: "Hello <World>, <this is a test>",
Syntax: "",
Expiration: exp,
Address: "::ffff:127.0.0.1",
}
err = qbin.Store(&doc)
if err != nil {
t.Error(err)
t.FailNow()
}
t.Logf("Stored document as %s", doc.ID)
doc2, err := qbin.Request(doc.ID, true)
if err != nil {
t.Error(err)
t.FailNow()
}
if doc2.Content != doc.Content {
t.Errorf("Content mismatch, received: %s (expected: %s)", doc2.Content, doc.Content)
}
if doc2.Address != doc.Address {
t.Errorf("Address mismatch, received: %s (expected: %s)", doc2.Address, doc.Address)
}
if doc2.Syntax != doc.Syntax {
t.Errorf("Syntax mismatch, received: %s (expected: %s)", doc2.Syntax, doc.Syntax)
}
if doc2.Upload != doc.Upload {
t.Errorf("Upload mismatch, received: %s (expected %s)", doc2.Upload, doc.Upload)
}
if doc2.Expiration != doc.Expiration {
t.Errorf("Expiration mismatch, received: %s (expected %s)", doc2.Expiration, doc.Expiration)
}
}