t0010-basic-commands.sh 3.1 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

test_expect_success "current dir is writable" '
Łukasz Magiera's avatar
Łukasz Magiera committed
12
  echo "It works!" >test.txt
Christian Couder's avatar
Christian Couder committed
13 14 15
'

test_expect_success "ipfs version succeeds" '
Łukasz Magiera's avatar
Łukasz Magiera committed
16
  ipfs version >version.txt
Christian Couder's avatar
Christian Couder committed
17 18
'

19
test_expect_success "ipfs --version success" '
Łukasz Magiera's avatar
Łukasz Magiera committed
20
  ipfs --version
21 22
'

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

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

'

Jakub Sztandera's avatar
Jakub Sztandera committed
36
test_expect_success "ipfs version --all has all required fields" '
Łukasz Magiera's avatar
Łukasz Magiera committed
37 38 39 40 41
  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
Jakub Sztandera's avatar
Jakub Sztandera committed
42 43
'

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

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

54
test_expect_success "'ipfs commands' succeeds" '
Łukasz Magiera's avatar
Łukasz Magiera committed
55
  ipfs commands >commands.txt
56 57 58
'

test_expect_success "'ipfs commands' output looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
59 60 61
  grep "ipfs add" commands.txt &&
  grep "ipfs daemon" commands.txt &&
  grep "ipfs update" commands.txt
62 63 64
'

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

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

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

  if [ $(cat fail) = 1 ]; then
    return 1
  fi
89 90
'

91
test_expect_failure "All ipfs commands docs are 80 columns or less" '
Łukasz Magiera's avatar
Łukasz Magiera committed
92 93 94 95 96
  echo 0 > fail
  while read cmd
  do
    LENGTH="$($cmd --help | awk "{ print length }" | sort -nr | head -1)"
    [ $LENGTH -gt 80 ] &&
97
      { echo "$cmd help text is longer than 79 chars ($LENGTH)"; echo 1 > fail; }
Łukasz Magiera's avatar
Łukasz Magiera committed
98 99 100 101 102
  done <commands.txt

  if [ $(cat fail) = 1 ]; then
    return 1
  fi
103 104
'

105 106 107 108 109
test_expect_success "All ipfs commands fail when passed a bad flag" '
  echo 0 > fail
  while read -r cmd
  do
    test_must_fail $cmd --badflag >/dev/null ||
110
      { echo "$cmd exit with code 0 when passed --badflag"; echo 1 > fail; }
111 112 113 114 115 116 117
  done <commands.txt

  if [ $(cat fail) = 1 ]; then
    return 1
  fi
'

118
test_expect_success "'ipfs commands --flags' succeeds" '
Łukasz Magiera's avatar
Łukasz Magiera committed
119
  ipfs commands --flags >commands.txt
120 121 122
'

test_expect_success "'ipfs commands --flags' output looks good" '
Łukasz Magiera's avatar
Łukasz Magiera committed
123 124 125
  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
126 127
'

Jakub Sztandera's avatar
Jakub Sztandera committed
128 129


Christian Couder's avatar
Christian Couder committed
130
test_done