github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/test/sharness/t0020-init.sh (about)

     1  #!/bin/sh
     2  #
     3  # Copyright (c) 2014 Christian Couder
     4  # MIT Licensed; see the LICENSE file in this repository.
     5  #
     6  
     7  test_description="Test init command"
     8  
     9  . lib/test-lib.sh
    10  
    11  # test that ipfs fails to init if IPFS_PATH isnt writeable
    12  test_expect_success "create dir and change perms succeeds" '
    13  	export IPFS_PATH="$(pwd)/.badipfs" &&
    14  	mkdir "$IPFS_PATH" &&
    15  	chmod 000 "$IPFS_PATH"
    16  '
    17  
    18  test_expect_success "ipfs init fails" '
    19  	test_must_fail ipfs init 2> init_fail_out
    20  '
    21  
    22  test_expect_success "ipfs init output looks good" '
    23  	echo "Error: failed to take lock at $IPFS_PATH: permission denied" > init_fail_exp &&
    24  	test_cmp init_fail_exp init_fail_out
    25  '
    26  
    27  # test no repo error message
    28  # this applies to `ipfs add sth`, `ipfs refs <hash>`
    29  test_expect_success "ipfs cat fails" '
    30      export IPFS_PATH="$(pwd)/.ipfs" &&
    31      test_must_fail ipfs cat Qmaa4Rw81a3a1VEx4LxB7HADUAXvZFhCoRdBzsMZyZmqHD 2> cat_fail_out
    32  '
    33  
    34  test_expect_success "ipfs cat no repo message looks good" '
    35      echo "Error: no ipfs repo found in $IPFS_PATH." > cat_fail_exp &&
    36      echo "please run: ipfs init" >> cat_fail_exp &&
    37      test_cmp cat_fail_exp cat_fail_out
    38  '
    39  
    40  # test that init succeeds
    41  test_expect_success "ipfs init succeeds" '
    42  	export IPFS_PATH="$(pwd)/.ipfs" &&
    43  	BITS="2048" &&
    44  	ipfs init --bits="$BITS" >actual_init
    45  '
    46  
    47  test_expect_success ".ipfs/ has been created" '
    48  	test -d ".ipfs" &&
    49  	test -f ".ipfs/config" &&
    50  	test -d ".ipfs/datastore" &&
    51  	test -d ".ipfs/blocks" ||
    52  	test_fsh ls -al .ipfs
    53  '
    54  
    55  test_expect_success "ipfs config succeeds" '
    56  	echo leveldb >expected_config &&
    57  	ipfs config Datastore.Type >actual_config &&
    58  	test_cmp expected_config actual_config
    59  '
    60  
    61  test_check_peerid() {
    62  	test $(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") = "46"
    63  }
    64  
    65  test_expect_success "ipfs peer id looks good" '
    66  	PEERID=$(ipfs config Identity.PeerID) &&
    67  	test_check_peerid "$PEERID"
    68  '
    69  
    70  test_expect_success "ipfs init output looks good" '
    71  	STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme" &&
    72  	echo "initializing ipfs node at $IPFS_PATH" >expected &&
    73  	echo "generating $BITS-bit RSA keypair...done" >>expected &&
    74  	echo "peer identity: $PEERID" >>expected &&
    75  	echo "to get started, enter:" >>expected &&
    76  	printf "\\n\\t$STARTFILE\\n\\n" >>expected &&
    77  	test_cmp expected actual_init
    78  '
    79  
    80  test_expect_success "Welcome readme exists" '
    81  	ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme
    82  '
    83  
    84  test_expect_success "clean up ipfs dir" '
    85  	rm -rf "$IPFS_PATH"
    86  '
    87  
    88  test_expect_success "'ipfs init --empty-repo' succeeds" '
    89  	BITS="1024" &&
    90  	ipfs init --bits="$BITS" --empty-repo >actual_init
    91  '
    92  
    93  test_expect_success "ipfs peer id looks good" '
    94  	PEERID=$(ipfs config Identity.PeerID) &&
    95  	test_check_peerid "$PEERID"
    96  '
    97  
    98  test_expect_success "'ipfs init --empty-repo' output looks good" '
    99  	echo "initializing ipfs node at $IPFS_PATH" >expected &&
   100  	echo "generating $BITS-bit RSA keypair...done" >>expected &&
   101  	echo "peer identity: $PEERID" >>expected &&
   102  	test_cmp expected actual_init
   103  '
   104  
   105  test_expect_success "Welcome readme doesn't exists" '
   106  	test_must_fail ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme
   107  '
   108  
   109  test_expect_success "clean up ipfs dir" '
   110  	rm -rf "$IPFS_PATH"
   111  '
   112  
   113  test_init_ipfs
   114  
   115  test_launch_ipfs_daemon
   116  
   117  test_expect_success "ipfs init should not run while daemon is running" '
   118  	test_must_fail ipfs init 2> daemon_running_err &&
   119  	EXPECT="Error: ipfs daemon is running. please stop it to run this command" &&
   120  	grep "$EXPECT" daemon_running_err
   121  '
   122  
   123  test_kill_ipfs_daemon
   124  
   125  test_done