tests for Daemon Listener #59
using IDfromPubKey
llSourcell committed
Sep 15, 2014 at 13:30 UTC
8eb13eb6bede10b5841fe72bc385de8f13f7c923
1 file changed
+67
daemon/daemon_test.go
new
+67
@@ -0,0 +1,67 @@
1
+package daemon
2
+
3
+import (
4
+ "testing"
5
+ "encoding/base64"
6
+ config "github.com/jbenet/go-ipfs/config"
7
+ core "github.com/jbenet/go-ipfs/core"
8
+ ci "github.com/jbenet/go-ipfs/crypto"
9
+ identify "github.com/jbenet/go-ipfs/identify"
10
+)
11
+
12
+func TestDaemonListener(t *testing.T) {
13
+
14
+
15
+ priv, pub, err := ci.GenerateKeyPair(ci.RSA, 512)
16
+ if err != nil {
17
+ t.Fatal(err)
18
+ }
19
+ prbytes, err := priv.Bytes()
20
+ if err != nil {
21
+ t.Fatal(err)
22
+ }
23
+
24
+ ident, _ := identify.IDFromPubKey(pub)
25
+ privKey := base64.StdEncoding.EncodeToString(prbytes)
26
+ pID := ident.Pretty()
27
+
28
+
29
+ id := &config.Identity{
30
+ PeerID: pID,
31
+ Address: "/ip4/127.0.0.1/tcp/8000",
32
+ PrivKey: privKey,
33
+ }
34
+
35
+ nodeConfigs := []*config.Config{
36
+ &config.Config{
37
+ Identity: id,
38
+ Datastore: config.Datastore{
39
+ Type: "memory",
40
+ },
41
+ },
42
+
43
+ &config.Config{
44
+ Identity: id,
45
+ Datastore: config.Datastore{
46
+ Type: "leveldb",
47
+ Path: ".testdb",
48
+ },
49
+ },
50
+ }
51
+
52
+ for _, c := range nodeConfigs {
53
+
54
+ node, _ := core.NewIpfsNode(c, false)
55
+ dl, initErr := NewDaemonListener(node, "localhost:1327")
56
+ if initErr != nil {
57
+ t.Fatal(initErr)
58
+ }
59
+
60
+ closeErr := dl.Close()
61
+ if closeErr != nil {
62
+ t.Fatal(closeErr)
63
+ }
64
+
65
+ }
66
+
67
+}