|
| 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 | +num_nodes=4 |
| 14 | + |
| 15 | +ipfsi() { |
| 16 | + dir="$1" |
| 17 | + shift |
| 18 | + IPFS_PATH="$IPTB_ROOT/$dir" ipfs $@ |
| 19 | +} |
| 20 | + |
| 21 | +test_expect_success "set up an iptb cluster" ' |
| 22 | + iptb init -n $num_nodes -p 0 -f --bootstrap=none |
| 23 | +' |
| 24 | + |
| 25 | +check_has_connection() { |
| 26 | + node=$1 |
| 27 | + ipfsi $node swarm peers | grep ipfs > /dev/null |
| 28 | +} |
| 29 | + |
| 30 | +startup_cluster() { |
| 31 | + bound=`expr $num_nodes - 1` |
| 32 | + test_expect_success "start up nodes" ' |
| 33 | + iptb start |
| 34 | + ' |
| 35 | + |
| 36 | + test_expect_success "connect nodes to eachother" ' |
| 37 | + iptb connect [1-$bound] 0 |
| 38 | + ' |
| 39 | + |
| 40 | + test_expect_success "nodes are connected" ' |
| 41 | + for i in `seq $bound` |
| 42 | + do |
| 43 | + if ! check_has_connection $i; then |
| 44 | + echo "oh shit guys" |
| 45 | + return 1 |
| 46 | + fi |
| 47 | + done |
| 48 | + ' |
| 49 | +} |
| 50 | + |
| 51 | +startup_cluster $num_nodes |
| 52 | + |
| 53 | +test_expect_success "add an obect on one node" ' |
| 54 | + echo "ipns is super fun" > file && |
| 55 | + HASH_FILE=$(ipfsi 1 add -q file) |
| 56 | +' |
| 57 | + |
| 58 | +test_expect_success "publish that object as an ipns entry" ' |
| 59 | + ipfsi 1 name publish $HASH_FILE |
| 60 | +' |
| 61 | + |
| 62 | +test_expect_success "add an entry on another node pointing to that one" ' |
| 63 | + NODE1_ID=$(iptb get id 1) && |
| 64 | + ipfsi 2 name publish /ipns/$NODE1_ID |
| 65 | +' |
| 66 | + |
| 67 | +test_expect_success "cat that entry on a third node" ' |
| 68 | + NODE2_ID=$(iptb get id 2) && |
| 69 | + ipfsi 3 cat /ipns/$NODE2_ID > output |
| 70 | +' |
| 71 | + |
| 72 | +test_expect_success "ensure output was the same" ' |
| 73 | + test_cmp file output |
| 74 | +' |
| 75 | + |
| 76 | +test_expect_success "shut down iptb" ' |
| 77 | + iptb stop |
| 78 | +' |
| 79 | + |
| 80 | +test_done |
0 commit comments