forked from holochain/holochain-proto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nucleus_test.go
62 lines (53 loc) · 1.88 KB
/
nucleus_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
package holochain
import (
"fmt"
. "github.com/smartystreets/goconvey/convey"
"os"
"testing"
)
func TestNewNucleus(t *testing.T) {
d := SetupTestDir()
defer CleanupTestDir(d)
var h Holochain
h.rootPath = d
os.MkdirAll(h.DBPath(), os.ModePerm)
nucleus := NewNucleus(&h, &DNA{})
Convey("It should initialize the Nucleus struct", t, func() {
So(nucleus.h, ShouldEqual, &h)
So(nucleus.alog, ShouldEqual, &h.Config.Loggers.App)
})
}
func TestAppMessages(t *testing.T) {
d, _, h := PrepareTestChain("test")
defer CleanupTestChain(h, d)
// no need to activate DHT protocols for this test
h.Config.PeerModeDHTNode = false
if err := h.Activate(); err != nil {
panic(err)
}
Convey("it should fail on incorrect body types", t, func() {
msg := h.node.NewMessage(APP_MESSAGE, GetReq{})
_, err := h.Send(h.node.ctx, ActionProtocol, h.node.HashAddr, msg, 0)
So(err.Error(), ShouldEqual, "Unexpected request body type 'holochain.GetReq' in send request, expecting holochain.AppMsg")
})
Convey("it should fail on unknown zomes", t, func() {
msg := h.node.NewMessage(APP_MESSAGE, AppMsg{ZomeType: "foo"})
_, err := h.Send(h.node.ctx, ActionProtocol, h.node.HashAddr, msg, 0)
So(err.Error(), ShouldEqual, "unknown zome: foo")
})
Convey("it should send and receive app messages", t, func() {
msg := h.node.NewMessage(APP_MESSAGE, AppMsg{ZomeType: "jsSampleZome", Body: `{"ping":"foobar"}`})
r, err := h.Send(h.node.ctx, ActionProtocol, h.node.HashAddr, msg, 0)
So(err, ShouldBeNil)
So(fmt.Sprintf("%v", r), ShouldEqual, `{jsSampleZome {"pong":"foobar"}}`)
})
}
func TestNewUUID(t *testing.T) {
var dna DNA
Convey("It should initialize dna's UUID", t, func() {
So(fmt.Sprintf("%v", dna.UUID), ShouldEqual, "00000000-0000-0000-0000-000000000000")
err := dna.NewUUID()
So(err, ShouldBeNil)
So(fmt.Sprintf("%v", dna.UUID), ShouldNotEqual, "00000000-0000-0000-0000-000000000000")
})
}