core_test.go 4.65 KB
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2 3
package core

import (
Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
4
	"testing"
Jeromy's avatar
Jeromy committed
5 6

	config "github.com/jbenet/go-ipfs/config"
7
	"github.com/jbenet/go-ipfs/peer"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
8 9
)

10
func TestInitialization(t *testing.T) {
11
	id := testIdentity
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
12

Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
13
	good := []*config.Config{
Brian Tiger Chow's avatar
Brian Tiger Chow committed
14
		&config.Config{
15
			Identity: id,
Brian Tiger Chow's avatar
Brian Tiger Chow committed
16
			Datastore: config.Datastore{
17 18
				Type: "memory",
			},
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
19 20 21 22
			Addresses: config.Addresses{
				Swarm: "/ip4/0.0.0.0/tcp/4001",
				API:   "/ip4/127.0.0.1/tcp/8000",
			},
23 24
		},

Brian Tiger Chow's avatar
Brian Tiger Chow committed
25
		&config.Config{
26
			Identity: id,
Brian Tiger Chow's avatar
Brian Tiger Chow committed
27
			Datastore: config.Datastore{
28 29 30
				Type: "leveldb",
				Path: ".testdb",
			},
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
31 32 33 34
			Addresses: config.Addresses{
				Swarm: "/ip4/0.0.0.0/tcp/4001",
				API:   "/ip4/127.0.0.1/tcp/8000",
			},
35
		},
Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
36
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
37

Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
38
	bad := []*config.Config{
Brian Tiger Chow's avatar
Brian Tiger Chow committed
39 40
		&config.Config{Identity: id, Datastore: config.Datastore{}},
		&config.Config{Identity: id, Datastore: config.Datastore{Type: "badtype"}},
Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
41
		&config.Config{},
Brian Tiger Chow's avatar
Brian Tiger Chow committed
42
		&config.Config{Datastore: config.Datastore{Type: "memory"}},
Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
43 44
		nil,
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
45

Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
46
	for i, c := range good {
Jeromy's avatar
Jeromy committed
47
		n, err := NewIpfsNode(c, false)
Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
48 49 50 51
		if n == nil || err != nil {
			t.Error("Should have constructed.", i, err)
		}
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
52

Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
53
	for i, c := range bad {
Jeromy's avatar
Jeromy committed
54
		n, err := NewIpfsNode(c, false)
Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
55 56 57 58
		if n != nil || err == nil {
			t.Error("Should have failed to construct.", i)
		}
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
59
}
60

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
func TestPeerIsLocal(t *testing.T) {
	t.Log("Ensure that peer is Local after initializing identity")

	online := false
	peers := peer.NewPeerstore()

	cfg := testIdentity
	p, err := initIdentity(&cfg, peers, online)
	if err != nil {
		t.Fatal(err)
	}
	if p.GetType() != peer.Local {
		t.Fail()
	}
}

77 78 79 80
var testIdentity = config.Identity{
	PeerID:  "QmNgdzLieYi8tgfo2WfTUzNVH5hQK9oAYGVf6dxN12NrHt",
	PrivKey: "CAASrRIwggkpAgEAAoICAQCwt67GTUQ8nlJhks6CgbLKOx7F5tl1r9zF4m3TUrG3Pe8h64vi+ILDRFd7QJxaJ/n8ux9RUDoxLjzftL4uTdtv5UXl2vaufCc/C0bhCRvDhuWPhVsD75/DZPbwLsepxocwVWTyq7/ZHsCfuWdoh/KNczfy+Gn33gVQbHCnip/uhTVxT7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