提交 2c1c48a1 作者: Jeromy

Add iptb sharness test for multi-ipns name resolution

上级 c1560bef
......@@ -38,7 +38,7 @@
},
{
"ImportPath":"github.com/whyrusleeping/iptb",
"Rev": "5ee5bc0bb43502dfc798786a78df2448c91dd764"
"Rev": "7f5790b9a136aca057bc8f1dc711e204c6343504"
},
{
"ImportPath": "github.com/Sirupsen/logrus",
......
#Ipfs Testbed
# IPTB
iptb is a program used to manage a cluster of ipfs nodes locally on your
computer. It allows the creation of up to 1000 (limited by poor port choice)
nodes, and allows for various other setup options to be selected such as
different bootstrapping patterns. iptb makes testing networks in ipfs
easy!
##commands:
### Commands:
- init
- creates and initializes 'n' repos
- Options:
- -n=[number of nodes]
- -f : force overwriting of existing nodes
- -bootstrap : select bootstrapping style for cluster choices: star, none
- start
- starts up all testbed nodes
- Options:
- -wait : wait until daemons are fully initialized
- stop
- kills all testbed nodes
- restart
- kills and then restarts all testbed nodes
### init -n=[number of nodes]
creates and initializes 'n' repos
- shell [n]
- execs your shell with environment variables set as follows:
- IPFS_PATH - set to testbed node n's IPFS_PATH
- NODE[x] - set to the peer ID of node x
### start
starts up all testbed nodes
### Configuration
By default, iptb uses `$HOME/testbed` to store created nodes. This path is
configurable via the environment variables `IPTB_ROOT`.
### stop
kills all testbed nodes
### restart
kills, then restarts all testbed nodes
### shell [n]
execs your shell with environment variables set as follows:
- IPFS_PATH - set to testbed node n's IPFS_PATH
- NODE[x] - set to the peer ID of node x
package main
import (
"errors"
"flag"
"fmt"
serial "github.com/ipfs/go-ipfs/repo/fsrepo/serialize"
"io/ioutil"
"log"
"net"
......@@ -14,6 +14,8 @@ import (
"sync"
"syscall"
"time"
serial "github.com/ipfs/go-ipfs/repo/fsrepo/serialize"
)
// GetNumNodes returns the number of testbed nodes configured in the testbed directory
......@@ -313,6 +315,15 @@ func IpfsShell(n int) error {
return syscall.Exec(shell, []string{shell}, nenvs)
}
func GetAttr(attr string, node int) (string, error) {
switch attr {
case "id":
return GetPeerID(node)
default:
return "", errors.New("unrecognized attribute")
}
}
var helptext = `Ipfs Testbed
Commands:
......@@ -340,6 +351,10 @@ Commands:
IPFS_PATH - set to testbed node n's IPFS_PATH
NODE[x] - set to the peer ID of node x
get [attribute] [node]
get an attribute of the given node
currently supports: "id"
Env Vars:
IPTB_ROOT:
......@@ -348,7 +363,7 @@ IPTB_ROOT:
func handleErr(s string, err error) {
if err != nil {
fmt.Println(s, err)
fmt.Fprintln(os.Stderr, s, err)
os.Exit(1)
}
}
......@@ -396,6 +411,18 @@ func main() {
err = IpfsShell(n)
handleErr("ipfs shell err: ", err)
case "get":
if len(flag.Args()) < 3 {
fmt.Println("iptb get [attr] [node]")
os.Exit(1)
}
attr := flag.Arg(1)
num, err := strconv.Atoi(flag.Arg(2))
handleErr("error parsing node number: ", err)
val, err := GetAttr(attr, num)
handleErr("error getting attribute: ", err)
fmt.Println(val)
default:
flag.Usage()
os.Exit(1)
......
#!/bin/sh
#
# Copyright (c) 2014 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#
test_description="Test ipfs repo operations"
. lib/test-lib.sh
export IPTB_ROOT="`pwd`/.iptb"
test_expect_success "set up an iptb cluster" '
iptb -n=4 init &&
iptb -wait start
'
test_expect_success "add an obect on one node" '
export IPFS_PATH="$IPTB_ROOT/1"
echo "ipns is super fun" > file &&
HASH_FILE=`ipfs add -q file`
'
test_expect_success "publish that object as an ipns entry" '
ipfs name publish $HASH_FILE
'
test_expect_success "add an entry on another node pointing to that one" '
export IPFS_PATH="$IPTB_ROOT/2"
NODE1_ID=`iptb get id 1` &&
ipfs name publish /ipns/$NODE1_ID
'
test_expect_success "cat that entry on a third node" '
export IPFS_PATH="$IPTB_ROOT/3"
NODE2_ID=`iptb get id 2` &&
ipfs cat /ipns/$NODE2_ID > output
'
test_expect_success "ensure output was the same" '
test_cmp file output
'
test_expect_success "shut down iptb" '
iptb stop
'
test_done
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论