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

import (
llSourcell's avatar
llSourcell committed
4
	"encoding/base64"
llSourcell's avatar
llSourcell committed
5 6 7 8
	config "github.com/jbenet/go-ipfs/config"
	core "github.com/jbenet/go-ipfs/core"
	ci "github.com/jbenet/go-ipfs/crypto"
	identify "github.com/jbenet/go-ipfs/identify"
llSourcell's avatar
llSourcell committed
9
	"testing"
llSourcell's avatar
llSourcell committed
10 11
)

llSourcell's avatar
llSourcell committed
12
func TestInitializeDaemonListener(t *testing.T) {
llSourcell's avatar
llSourcell committed
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

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

	ident, _ := identify.IDFromPubKey(pub)
	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)
		dl, initErr := NewDaemonListener(node, "localhost:1327")
		if initErr != nil {
			t.Fatal(initErr)
		}

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

	}

}