mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 19:24:14 +08:00
67
daemon/daemon_test.go
Normal file
67
daemon/daemon_test.go
Normal file
@ -0,0 +1,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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user