Add iptb sharness test for multi-ipns name resolution
Jeromy committed
Apr 23, 2015 at 00:54 UTC
2c1c48a165c9c865adc38a986d8a736132d61bc3
4 files changed
+106
-17
Godeps/Godeps.json
+1
-1
@@ -38,7 +38,7 @@
38
},
39
{
40
"ImportPath":"github.com/whyrusleeping/iptb",
41
- "Rev": "5ee5bc0bb43502dfc798786a78df2448c91dd764"
41
+ "Rev": "7f5790b9a136aca057bc8f1dc711e204c6343504"
42
},
43
{
44
"ImportPath": "github.com/Sirupsen/logrus",
Godeps/_workspace/src/github.com/whyrusleeping/iptb/README.md
+28
-14
@@ -1,20 +1,34 @@
1
-#Ipfs Testbed
1
+# IPTB
2
+iptb is a program used to manage a cluster of ipfs nodes locally on your
3
+computer. It allows the creation of up to 1000 (limited by poor port choice)
4
+nodes, and allows for various other setup options to be selected such as
5
+different bootstrapping patterns. iptb makes testing networks in ipfs
6
+easy!
7
3
-##commands:
8
+### Commands:
9
+- init
10
+ - creates and initializes 'n' repos
11
+ - Options:
12
+ - -n=[number of nodes]
13
+ - -f : force overwriting of existing nodes
14
+ - -bootstrap : select bootstrapping style for cluster choices: star, none
15
+- start
16
+ - starts up all testbed nodes
17
+ - Options:
18
+ - -wait : wait until daemons are fully initialized
19
+- stop
20
+ - kills all testbed nodes
21
+- restart
22
+ - kills and then restarts all testbed nodes
23
5
-### init -n=[number of nodes]
6
-creates and initializes 'n' repos
24
+- shell [n]
25
+ - execs your shell with environment variables set as follows:
26
+ - IPFS_PATH - set to testbed node n's IPFS_PATH
27
+ - NODE[x] - set to the peer ID of node x
28
8
-### start
9
-starts up all testbed nodes
29
+### Configuration
30
+By default, iptb uses `$HOME/testbed` to store created nodes. This path is
31
+configurable via the environment variables `IPTB_ROOT`.
32
11
-### stop
12
-kills all testbed nodes
33
14
-### restart
15
-kills, then restarts all testbed nodes
34
17
-### shell [n]
18
-execs your shell with environment variables set as follows:
19
-- IPFS_PATH - set to testbed node n's IPFS_PATH
20
-- NODE[x] - set to the peer ID of node x
Godeps/_workspace/src/github.com/whyrusleeping/iptb/main.go
+29
-2
@@ -1,9 +1,9 @@
1
package main
2
3
import (
4
+ "errors"
5
"flag"
6
"fmt"
6
- serial "github.com/ipfs/go-ipfs/repo/fsrepo/serialize"
7
"io/ioutil"
8
"log"
9
"net"
@@ -14,6 +14,8 @@ import (
14
"sync"
15
"syscall"
16
"time"
17
+
18
+ serial "github.com/ipfs/go-ipfs/repo/fsrepo/serialize"
19
)
20
21
// GetNumNodes returns the number of testbed nodes configured in the testbed directory
@@ -313,6 +315,15 @@ func IpfsShell(n int) error {
315
return syscall.Exec(shell, []string{shell}, nenvs)
316
}
317
318
+func GetAttr(attr string, node int) (string, error) {
319
+ switch attr {
320
+ case "id":
321
+ return GetPeerID(node)
322
+ default:
323
+ return "", errors.New("unrecognized attribute")
324
+ }
325
+}
326
+
327
var helptext = `Ipfs Testbed
328
329
Commands:
@@ -340,6 +351,10 @@ Commands:
351
IPFS_PATH - set to testbed node n's IPFS_PATH
352
NODE[x] - set to the peer ID of node x
353
354
+ get [attribute] [node]
355
+ get an attribute of the given node
356
+ currently supports: "id"
357
+
358
Env Vars:
359
360
IPTB_ROOT:
@@ -348,7 +363,7 @@ IPTB_ROOT:
363
364
func handleErr(s string, err error) {
365
if err != nil {
351
- fmt.Println(s, err)
366
+ fmt.Fprintln(os.Stderr, s, err)
367
os.Exit(1)
368
}
369
}
@@ -396,6 +411,18 @@ func main() {
411
412
err = IpfsShell(n)
413
handleErr("ipfs shell err: ", err)
414
+ case "get":
415
+ if len(flag.Args()) < 3 {
416
+ fmt.Println("iptb get [attr] [node]")
417
+ os.Exit(1)
418
+ }
419
+ attr := flag.Arg(1)
420
+ num, err := strconv.Atoi(flag.Arg(2))
421
+ handleErr("error parsing node number: ", err)
422
+
423
+ val, err := GetAttr(attr, num)
424
+ handleErr("error getting attribute: ", err)
425
+ fmt.Println(val)
426
default:
427
flag.Usage()
428
os.Exit(1)
test/sharness/t0101-iptb-name.sh
new
+48
@@ -0,0 +1,48 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2014 Jeromy Johnson
4
+# MIT Licensed; see the LICENSE file in this repository.
5
+#
6
+
7
+test_description="Test ipfs repo operations"
8
+
9
+. lib/test-lib.sh
10
+
11
+export IPTB_ROOT="`pwd`/.iptb"
12
+
13
+test_expect_success "set up an iptb cluster" '
14
+ iptb -n=4 init &&
15
+ iptb -wait start
16
+'
17
+
18
+test_expect_success "add an obect on one node" '
19
+ export IPFS_PATH="$IPTB_ROOT/1"
20
+ echo "ipns is super fun" > file &&
21
+ HASH_FILE=`ipfs add -q file`
22
+'
23
+
24
+test_expect_success "publish that object as an ipns entry" '
25
+ ipfs name publish $HASH_FILE
26
+'
27
+
28
+test_expect_success "add an entry on another node pointing to that one" '
29
+ export IPFS_PATH="$IPTB_ROOT/2"
30
+ NODE1_ID=`iptb get id 1` &&
31
+ ipfs name publish /ipns/$NODE1_ID
32
+'
33
+
34
+test_expect_success "cat that entry on a third node" '
35
+ export IPFS_PATH="$IPTB_ROOT/3"
36
+ NODE2_ID=`iptb get id 2` &&
37
+ ipfs cat /ipns/$NODE2_ID > output
38
+'
39
+
40
+test_expect_success "ensure output was the same" '
41
+ test_cmp file output
42
+'
43
+
44
+test_expect_success "shut down iptb" '
45
+ iptb stop
46
+'
47
+
48
+test_done