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

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

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

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

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

26
	ident, _ := spipe.IDFromPubKey(pub)
llSourcell's avatar
llSourcell committed
27 28 29
	privKey := base64.StdEncoding.EncodeToString(prbytes)
	pID := ident.Pretty()

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
30
	id := config.Identity{
llSourcell's avatar
llSourcell committed
31 32 33 34 35 36 37 38 39 40
		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
41 42 43 44
			Addresses: config.Addresses{
				Swarm: "/ip4/0.0.0.0/tcp/4001",
				API:   "/ip4/127.0.0.1/tcp/8000",
			},
llSourcell's avatar
llSourcell committed
45 46 47 48 49 50
		},

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

60 61 62 63 64 65
	var tempConfigDir = ".test"
	err = os.MkdirAll(tempConfigDir, os.ModeDir|0777)
	if err != nil {
		t.Fatalf("error making temp config dir: %v", err)
	}

llSourcell's avatar
llSourcell committed
66 67 68
	for _, c := range nodeConfigs {

		node, _ := core.NewIpfsNode(c, false)
69 70 71 72
		addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/1327")
		if err != nil {
			t.Fatal(err)
		}
73 74

		dl, initErr := NewDaemonListener(node, addr, tempConfigDir)
llSourcell's avatar
llSourcell committed
75 76 77 78 79 80 81 82 83 84 85 86
		if initErr != nil {
			t.Fatal(initErr)
		}

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

	}

}