github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/test/sharness/t0041-add-cat-offline.sh (about)

     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 add and cat commands"
     8  
     9  . lib/test-lib.sh
    10  
    11  client_err() {
    12      printf "$@\n\nUse 'ipfs add --help' for information about this command\n"
    13  }
    14  
    15  test_init_ipfs
    16  
    17  test_expect_success "ipfs add file succeeds" '
    18  	echo "some content" > afile &&
    19  	HASH=$(ipfs add -q afile)
    20  '
    21  
    22  test_expect_success "ipfs add output looks good" '
    23  	echo Qmb1EXrDyKhNWfvLPYK4do3M9nU7BuLAcbqBir6aUrDsRY > expected &&
    24  	echo $HASH > actual &&
    25  	test_cmp expected actual
    26  '
    27  
    28  test_expect_success "ipfs add --only-hash succeeds" '
    29  	ipfs add -q --only-hash afile > ho_output
    30  '
    31  
    32  test_expect_success "ipfs add --only-hash output looks good" '
    33  	test_cmp expected ho_output
    34  '
    35  
    36  test_expect_success "ipfs cat file suceeds" '
    37  	ipfs cat $HASH > out_1
    38  '
    39  
    40  test_expect_success "output looks good" '
    41  	test_cmp afile out_1
    42  '
    43  
    44  test_expect_success "ipfs cat /ipfs/file succeeds" '
    45  	ipfs cat /ipfs/$HASH > out_2
    46  '
    47  
    48  test_expect_success "output looks good" '
    49  	test_cmp afile out_2
    50  '
    51  
    52  test_expect_success "ipfs add --only-hash succeeds" '
    53  	echo "unknown content for only-hash" | ipfs add --only-hash -q > oh_hash
    54  '
    55  
    56  test_expect_success "ipfs cat file fails" '
    57  	test_must_fail ipfs cat $(cat oh_hash)
    58  '
    59  
    60  test_expect_success "useful error message when adding a named pipe" '
    61  	mkfifo named-pipe &&
    62  	test_expect_code 1 ipfs add named-pipe 2>actual &&
    63      client_err "Error: Unrecognized file type for named-pipe: $(generic_stat named-pipe)" >expected &&
    64  	test_cmp expected actual
    65  '
    66  
    67  test_expect_success "useful error message when recursively adding a named pipe" '
    68  	mkdir named-pipe-dir &&
    69  	mkfifo named-pipe-dir/named-pipe &&
    70  	test_expect_code 1 ipfs add -r named-pipe-dir 2>actual &&
    71      printf "Error: Unrecognized file type for named-pipe-dir/named-pipe: $(generic_stat named-pipe-dir/named-pipe)\n" >expected &&
    72  	test_cmp expected actual
    73  '
    74  
    75  test_done