This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
/
main_test.go
117 lines (103 loc) · 2.39 KB
/
main_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package core_test
import (
"crypto/rand"
. "github.com/textileio/textile-go/core"
"github.com/textileio/textile-go/keypair"
logger "gx/ipfs/QmQvJiADDe7JR4m968MwXobTCCzUqQkP87aRHe29MEBGHV/go-logging"
libp2pc "gx/ipfs/Qme1knMqwt1hKZbc1BmQFmnm9f36nyQGwXxPGVpVJ9rMK5/go-libp2p-crypto"
"os"
"testing"
)
var repoPath = "testdata/.textile"
var node *Textile
func TestInitRepo(t *testing.T) {
os.RemoveAll(repoPath)
accnt := keypair.Random()
if err := InitRepo(InitConfig{
Account: *accnt,
RepoPath: repoPath,
LogLevel: logger.ERROR,
}); err != nil {
t.Errorf("init node failed: %s", err)
}
}
func TestNewTextile(t *testing.T) {
var err error
node, err = NewTextile(RunConfig{
RepoPath: repoPath,
LogLevel: logger.ERROR,
})
if err != nil {
t.Errorf("create node failed: %s", err)
}
}
func TestCore_Start(t *testing.T) {
if err := node.Start(); err != nil {
t.Errorf("start node failed: %s", err)
}
<-node.OnlineCh()
}
func TestCore_Started(t *testing.T) {
if !node.Started() {
t.Errorf("should report started")
}
}
func TestCore_Online(t *testing.T) {
if !node.Online() {
t.Errorf("should report online")
}
}
func TestCore_CafeRegister(t *testing.T) {
// TODO
}
func TestCore_AddThread(t *testing.T) {
sk, _, err := libp2pc.GenerateEd25519Key(rand.Reader)
if err != nil {
t.Error(err)
}
thrd, err := node.AddThread("test", sk, true)
if err != nil {
t.Errorf("add thread failed: %s", err)
return
}
if thrd == nil {
t.Error("add thread didn't return thread")
}
}
func TestCore_AddImage(t *testing.T) {
added, err := node.AddImageByPath("../images/testdata/image.jpg")
if err != nil {
t.Errorf("add image failed: %s", err)
return
}
if len(added.Id) == 0 {
t.Errorf("add image got bad id")
}
// test adding an image w/o the orientation tag
added2, err := node.AddImageByPath("../images/testdata/image-no-orientation.jpg")
if err != nil {
t.Errorf("add image w/o orientation tag failed: %s", err)
return
}
if len(added2.Id) == 0 {
t.Errorf("add photo w/o orientation tag got bad id")
}
}
func TestCore_Stop(t *testing.T) {
if err := node.Stop(); err != nil {
t.Errorf("stop node failed: %s", err)
}
}
func TestCore_StartedAgain(t *testing.T) {
if node.Started() {
t.Errorf("should report stopped")
}
}
func TestCore_OnlineAgain(t *testing.T) {
if node.Online() {
t.Errorf("should report offline")
}
}
func TestCore_Teardown(t *testing.T) {
node = nil
}