daemon_test.go 1.49 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
	privKey := base64.StdEncoding.EncodeToString(prbytes)
	pID := ident.Pretty()

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
29
	id := config.Identity{
llSourcell's avatar
llSourcell committed
30 31 32 33 34 35 36 37 38 39
		PeerID:  pID,
		PrivKey: privKey,
	}

	nodeConfigs := []*config.Config{
		&config.Config{
			Identity: id,
			Datastore: config.Datastore{
				Type: "memory",
			},
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
40 41 42 43
			Addresses: config.Addresses{
				Swarm: "/ip4/0.0.0.0/tcp/4001",
				API:   "/ip4/127.0.0.1/tcp/8000",
			},
llSourcell's avatar
llSourcell committed
44 45 46 47 48 49 50 51
		},

		&config.Config{
			Identity: id,
			Datastore: config.Datastore{
				Type: "leveldb",
				Path: ".testdb",
			},
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
52 53 54 55
			Addresses: config.Addresses{
				Swarm: "/ip4/0.0.0.0/tcp/4001",
				API:   "/ip4/127.0.0.1/tcp/8000",
			},
llSourcell's avatar
llSourcell committed
56 57 58 59 60 61
		},
	}

	for _, c := range nodeConfigs {

		node, _ := core.NewIpfsNode(c, false)
62 63 64 65
		addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/1327")
		if err != nil {
			t.Fatal(err)
		}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
66
		dl, initErr := NewDaemonListener(node, addr, ".")
llSourcell's avatar
llSourcell committed
67 68 69 70 71 72 73 74 75 76 77 78
		if initErr != nil {
			t.Fatal(initErr)
		}

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

	}

}