daemon_test.go 1.14 KB
Newer Older
llSourcell's avatar
llSourcell committed
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 63 64 65 66 67
package daemon

import (
	"testing"
    "encoding/base64"
	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"
)

func TestDaemonListener(t *testing.T) {


	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)
		}

	}

}