From 2c1c48a165c9c865adc38a986d8a736132d61bc3 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 23 Apr 2015 00:54:56 -0700 Subject: [PATCH] Add iptb sharness test for multi-ipns name resolution --- Godeps/Godeps.json | 2 +- .../github.com/whyrusleeping/iptb/README.md | 42 ++++++++++------ .../src/github.com/whyrusleeping/iptb/main.go | 31 +++++++++++- test/sharness/t0101-iptb-name.sh | 48 +++++++++++++++++++ 4 files changed, 106 insertions(+), 17 deletions(-) create mode 100755 test/sharness/t0101-iptb-name.sh diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 8b665ed70..e52de3c7d 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -38,7 +38,7 @@ }, { "ImportPath":"github.com/whyrusleeping/iptb", - "Rev": "5ee5bc0bb43502dfc798786a78df2448c91dd764" + "Rev": "7f5790b9a136aca057bc8f1dc711e204c6343504" }, { "ImportPath": "github.com/Sirupsen/logrus", diff --git a/Godeps/_workspace/src/github.com/whyrusleeping/iptb/README.md b/Godeps/_workspace/src/github.com/whyrusleeping/iptb/README.md index b1d176a88..1c3b9f284 100644 --- a/Godeps/_workspace/src/github.com/whyrusleeping/iptb/README.md +++ b/Godeps/_workspace/src/github.com/whyrusleeping/iptb/README.md @@ -1,20 +1,34 @@ -#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 diff --git a/Godeps/_workspace/src/github.com/whyrusleeping/iptb/main.go b/Godeps/_workspace/src/github.com/whyrusleeping/iptb/main.go index 46ff88239..d6fa9d9c1 100644 --- a/Godeps/_workspace/src/github.com/whyrusleeping/iptb/main.go +++ b/Godeps/_workspace/src/github.com/whyrusleeping/iptb/main.go @@ -1,9 +1,9 @@ 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) diff --git a/test/sharness/t0101-iptb-name.sh b/test/sharness/t0101-iptb-name.sh new file mode 100755 index 000000000..02f227dfb --- /dev/null +++ b/test/sharness/t0101-iptb-name.sh @@ -0,0 +1,48 @@ +#!/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