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

     1  #!/bin/sh
     2  #
     3  # Copyright (c) 2015 Matt Bell
     4  # MIT Licensed; see the LICENSE file in this repository.
     5  #
     6  
     7  test_description="Test get command"
     8  
     9  . lib/test-lib.sh
    10  
    11  test_init_ipfs
    12  
    13  # we use a function so that we can run it both offline + online
    14  test_get_cmd() {
    15  
    16  	test_expect_success "'ipfs get --help' succeeds" '
    17  		ipfs get --help >actual
    18  	'
    19  
    20  	test_expect_success "'ipfs get --help' output looks good" '
    21  		egrep "ipfs get.*<ipfs-path>" actual >/dev/null ||
    22  		test_fsh cat actual
    23  	'
    24  
    25  	test_expect_success "ipfs get succeeds" '
    26  		echo "Hello Worlds!" >data &&
    27  		HASH=`ipfs add -q data` &&
    28  		ipfs get "$HASH" >actual
    29  	'
    30  
    31  	test_expect_success "ipfs get output looks good" '
    32  		printf "%s\n\n" "Saving file(s) to $HASH" >expected &&
    33  		test_cmp expected actual
    34  	'
    35  
    36  	test_expect_success "ipfs get file output looks good" '
    37  		test_cmp "$HASH" data
    38  	'
    39  
    40  	test_expect_success "ipfs get DOES NOT error when trying to overwrite a file" '
    41  		ipfs get "$HASH" >actual &&
    42  		rm "$HASH"
    43  	'
    44  
    45  	test_expect_success "ipfs get -a succeeds" '
    46  		ipfs get "$HASH" -a >actual
    47  	'
    48  
    49  	test_expect_success "ipfs get -a output looks good" '
    50  		printf "%s\n\n" "Saving archive to $HASH.tar" >expected &&
    51  		test_cmp expected actual
    52  	'
    53  
    54  	# TODO: determine why this fails
    55  	test_expect_failure "ipfs get -a archive output is valid" '
    56  		tar -xf "$HASH".tar &&
    57  		test_cmp "$HASH" data &&
    58  		rm "$HASH".tar &&
    59  		rm "$HASH"
    60  	'
    61  
    62  	test_expect_success "ipfs get -a -C succeeds" '
    63  		ipfs get "$HASH" -a -C >actual
    64  	'
    65  
    66  	test_expect_success "ipfs get -a -C output looks good" '
    67  		printf "%s\n\n" "Saving archive to $HASH.tar.gz" >expected &&
    68  		test_cmp expected actual
    69  	'
    70  
    71  	# TODO(mappum)
    72  	test_expect_failure "gzipped tar archive output is valid" '
    73  		tar -zxf "$HASH".tar.gz &&
    74  		test_cmp "$HASH" data &&
    75  		rm "$HASH".tar.gz &&
    76  		rm "$HASH"
    77  	'
    78  
    79  	test_expect_success "ipfs get succeeds (directory)" '
    80  		mkdir -p dir &&
    81  		touch dir/a &&
    82  		mkdir -p dir/b &&
    83  		echo "Hello, Worlds!" >dir/b/c &&
    84  		HASH2=`ipfs add -r -q dir | tail -n 1` &&
    85  		ipfs get "$HASH2" >actual
    86  	'
    87  
    88  	test_expect_success "ipfs get output looks good (directory)" '
    89  		printf "%s\n\n" "Saving file(s) to $HASH2" >expected &&
    90  		test_cmp expected actual
    91  	'
    92  
    93  	test_expect_success "ipfs get output is valid (directory)" '
    94  		test_cmp dir/a "$HASH2"/a &&
    95  		test_cmp dir/b/c "$HASH2"/b/c &&
    96  		rm -r "$HASH2"
    97  	'
    98  
    99  	test_expect_success "ipfs get -a -C succeeds (directory)" '
   100  		ipfs get "$HASH2" -a -C >actual
   101  	'
   102  
   103  	test_expect_success "ipfs get -a -C output looks good (directory)" '
   104  		printf "%s\n\n" "Saving archive to $HASH2.tar.gz" >expected &&
   105  		test_cmp expected actual
   106  	'
   107  
   108  	# TODO(mappum)
   109  	test_expect_failure "gzipped tar archive output is valid (directory)" '
   110  		tar -zxf "$HASH2".tar.gz &&
   111  		test_cmp dir/a "$HASH2"/a &&
   112  		test_cmp dir/b/c "$HASH2"/b/c &&
   113  		rm -r "$HASH2"
   114  	'
   115  
   116  	test_expect_success "ipfs get ../.. should fail" '
   117  		echo "Error: invalid ipfs ref path" >expected &&
   118  		test_must_fail ipfs get ../.. 2>actual &&
   119  		test_cmp expected actual
   120  	'
   121  }
   122  
   123  # should work offline
   124  test_get_cmd
   125  
   126  # should work online
   127  test_launch_ipfs_daemon
   128  test_get_cmd
   129  test_kill_ipfs_daemon
   130  
   131  test_done