t0020-init.sh 2.09 KB
Newer Older
1 2 3 4 5 6 7 8
#!/bin/sh
#
# Copyright (c) 2014 Christian Couder
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test init command"

9
. lib/test-lib.sh
10

11 12 13 14 15 16 17 18 19 20 21 22
# test that ipfs fails to init if IPFS_PATH isnt writeable
test_expect_success "create dir and change perms succeeds" '
	export IPFS_PATH="$(pwd)/.badipfs" &&
	mkdir "$IPFS_PATH" &&
	chmod 000 "$IPFS_PATH"
'

test_expect_success "ipfs init fails" '
	test_must_fail ipfs init 2> init_fail_out
'

test_expect_success "ipfs init output looks good" '
Jeromy's avatar
Jeromy committed
23
	echo "Error: failed to take lock at $IPFS_PATH: permission denied" > init_fail_exp &&
24 25 26
	test_cmp init_fail_out init_fail_exp
'

27
test_expect_success "ipfs init succeeds" '
28
	export IPFS_PATH="$(pwd)/.ipfs" &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
29 30
	BITS="2048" &&
	ipfs init --bits="$BITS" >actual_init
31 32
'

33 34 35
test_expect_success ".ipfs/ has been created" '
	test -d ".ipfs" &&
	test -f ".ipfs/config" &&
36 37
	test -d ".ipfs/datastore" &&
	test -d ".ipfs/blocks" ||
38
	test_fsh ls -al .ipfs
39 40 41
'

test_expect_success "ipfs config succeeds" '
42 43 44
	echo leveldb >expected_config &&
	ipfs config Datastore.Type >actual_config &&
	test_cmp expected_config actual_config
45 46
'

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
47 48
test_expect_success "ipfs peer id looks good" '
	PEERID=$(ipfs config Identity.PeerID) &&
49 50 51
	echo $PEERID | tr -dC "[:alnum:]" | wc -c | tr -d " " >actual_peerid &&
	echo "46" >expected_peerid &&
	test_cmp expected_peerid actual_peerid
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
52
'
53

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
54
test_expect_success "ipfs init output looks good" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
55
	STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme" &&
56
	echo "initializing ipfs node at $IPFS_PATH" >expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
57
	echo "generating $BITS-bit RSA keypair...done" >>expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
58
	echo "peer identity: $PEERID" >>expected &&
59 60
	echo "to get started, enter:" >>expected &&
	printf "\\n\\t$STARTFILE\\n\\n" >>expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
61 62 63
	test_cmp expected actual_init
'

64 65 66 67
test_expect_success "clean up ipfs dir" '
	rm -rf "$IPFS_PATH"
'

68 69
test_init_ipfs

Travis Person's avatar
Travis Person committed
70 71
test_launch_ipfs_daemon

72 73 74 75
test_expect_success "ipfs init should not run while daemon is running" '
	test_must_fail ipfs init 2> daemon_running_err &&
	EXPECT="Error: ipfs daemon is running. please stop it to run this command" &&
	grep "$EXPECT" daemon_running_err
Travis Person's avatar
Travis Person committed
76 77 78 79
'

test_kill_ipfs_daemon

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
80
test_done