t0010-basic-commands.sh 2.4 KB
Newer Older
Christian Couder's avatar
Christian Couder committed
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 installation and some basic commands"

9
. lib/test-lib.sh
Christian Couder's avatar
Christian Couder committed
10 11 12 13 14 15 16 17 18

test_expect_success "current dir is writable" '
	echo "It works!" >test.txt
'

test_expect_success "ipfs version succeeds" '
	ipfs version >version.txt
'

19
test_expect_success "ipfs --version success" '
Jakub Sztandera's avatar
Jakub Sztandera committed
20
    ipfs --version
21 22
'

Christian Couder's avatar
Christian Couder committed
23
test_expect_success "ipfs version output looks good" '
24
	egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" version.txt >/dev/null ||
25
	test_fsh cat version.txt
Christian Couder's avatar
Christian Couder committed
26 27
'

28 29 30 31 32 33 34 35
test_expect_success "ipfs versions matches ipfs --version" '
    ipfs version > version.txt &&
    ipfs --version > version2.txt &&
    diff version2.txt version.txt ||
    test_fsh ipfs --version

'

Jakub Sztandera's avatar
Jakub Sztandera committed
36 37 38 39 40 41 42 43
test_expect_success "ipfs version --all has all required fields" '
	ipfs version --all > version_all.txt &&
	grep "go-ipfs version" version_all.txt &&
	grep "Repo version" version_all.txt &&
	grep "System version" version_all.txt &&
	grep "Golang version" version_all.txt
'

Christian Couder's avatar
Christian Couder committed
44 45 46 47 48
test_expect_success "ipfs help succeeds" '
	ipfs help >help.txt
'

test_expect_success "ipfs help output looks good" '
49
	egrep -i "^Usage" help.txt >/dev/null &&
Jakub Sztandera's avatar
Jakub Sztandera committed
50
	egrep "ipfs <command>" help.txt >/dev/null ||
51
	test_fsh cat help.txt
Christian Couder's avatar
Christian Couder committed
52 53
'

54 55 56 57 58 59 60 61 62 63 64
test_expect_success "'ipfs commands' succeeds" '
	ipfs commands >commands.txt
'

test_expect_success "'ipfs commands' output looks good" '
	grep "ipfs add" commands.txt &&
	grep "ipfs daemon" commands.txt &&
	grep "ipfs update" commands.txt
'

test_expect_success "All commands accept --help" '
Jakub Sztandera's avatar
Jakub Sztandera committed
65
	echo 0 > fail
66 67
	while read -r cmd
	do
Jakub Sztandera's avatar
Jakub Sztandera committed
68
		$cmd --help </dev/null >/dev/null ||
Jakub Sztandera's avatar
Jakub Sztandera committed
69
			{ echo $cmd doesnt accept --help; echo 1 > fail; }
70
	done <commands.txt
Jakub Sztandera's avatar
Jakub Sztandera committed
71

Jakub Sztandera's avatar
Jakub Sztandera committed
72
	if [ $(cat fail) = 1 ]; then
Jakub Sztandera's avatar
Jakub Sztandera committed
73 74 75 76 77
		return 1
	fi
'

test_expect_failure "All ipfs root commands are mentioned in base helptext" '
Jakub Sztandera's avatar
Jakub Sztandera committed
78 79
	echo 0 > fail
	cut -d" " -f 2 commands.txt | grep -v ipfs | sort -u | \
Jakub Sztandera's avatar
Jakub Sztandera committed
80 81 82
	while read cmd
	do
		grep "    $cmd" help.txt > /dev/null ||
Jakub Sztandera's avatar
Jakub Sztandera committed
83
			{ echo missing $cmd from helptext; echo 1 > fail; }
Jakub Sztandera's avatar
Jakub Sztandera committed
84 85
	done

Jakub Sztandera's avatar
Jakub Sztandera committed
86
	if [ $(cat fail) = 1 ]; then
Jakub Sztandera's avatar
Jakub Sztandera committed
87 88
		return 1
	fi
89 90
'

91 92 93 94 95 96 97 98 99 100
test_expect_success "'ipfs commands --flags' succeeds" '
	ipfs commands --flags >commands.txt
'

test_expect_success "'ipfs commands --flags' output looks good" '
	grep "ipfs pin add --recursive / ipfs pin add -r" commands.txt &&
	grep "ipfs id --format / ipfs id -f" commands.txt &&
	grep "ipfs repo gc --quiet / ipfs repo gc -q" commands.txt
'

Jakub Sztandera's avatar
Jakub Sztandera committed
101 102


Christian Couder's avatar
Christian Couder committed
103
test_done