daemon_test.go 1.3 KB
Newer Older
llSourcell's avatar
llSourcell committed
1 2 3
package daemon

import (
llSourcell's avatar
llSourcell committed
4
	"encoding/base64"
5 6 7
	"testing"

	ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
llSourcell's avatar
llSourcell committed
8 9 10
	config "github.com/jbenet/go-ipfs/config"
	core "github.com/jbenet/go-ipfs/core"
	ci "github.com/jbenet/go-ipfs/crypto"
11
	spipe "github.com/jbenet/go-ipfs/crypto/spipe"
llSourcell's avatar
llSourcell committed
12 13
)

llSourcell's avatar
llSourcell committed
14
func TestInitializeDaemonListener(t *testing.T) {
llSourcell's avatar
llSourcell committed
15 16 17 18 19 20 21 22 23 24

	priv, pub, err := ci.GenerateKeyPair(ci.RSA, 512)
	if err != nil {
		t.Fatal(err)
	}
	prbytes, err := priv.Bytes()
	if err != nil {
		t.Fatal(err)
	}

25
	ident, _ := spipe.IDFromPubKey(pub)
llSourcell's avatar
llSourcell committed
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
	privKey := base64.StdEncoding.EncodeToString(prbytes)
	pID := ident.Pretty()

	id := &config.Identity{
		PeerID:  pID,
		Address: "/ip4/127.0.0.1/tcp/8000",
		PrivKey: privKey,
	}

	nodeConfigs := []*config.Config{
		&config.Config{
			Identity: id,
			Datastore: config.Datastore{
				Type: "memory",
			},
		},

		&config.Config{
			Identity: id,
			Datastore: config.Datastore{
				Type: "leveldb",
				Path: ".testdb",
			},
		},
	}

	for _, c := range nodeConfigs {

		node, _ := core.NewIpfsNode(c, false)
55 56 57 58 59
		addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/1327")
		if err != nil {
			t.Fatal(err)
		}
		dl, initErr := NewDaemonListener(node, addr)
llSourcell's avatar
llSourcell committed
60 61 62 63 64 65 66 67 68 69 70 71
		if initErr != nil {
			t.Fatal(initErr)
		}

		closeErr := dl.Close()
		if closeErr != nil {
			t.Fatal(closeErr)
		}

	}

}