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

     1  #!/bin/sh
     2  #
     3  # Copyright (c) 2014 Christian Couder
     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_launch_ipfs_daemon_and_mount
    16  
    17  test_expect_success "'ipfs add --help' succeeds" '
    18  	ipfs add --help >actual
    19  '
    20  
    21  test_expect_success "'ipfs add --help' output looks good" '
    22  	egrep "ipfs add.*<path>" actual >/dev/null ||
    23  	test_fsh cat actual
    24  '
    25  
    26  test_expect_success "'ipfs cat --help' succeeds" '
    27  	ipfs cat --help >actual
    28  '
    29  
    30  test_expect_success "'ipfs cat --help' output looks good" '
    31  	egrep "ipfs cat.*<ipfs-path>" actual >/dev/null ||
    32  	test_fsh cat actual
    33  '
    34  
    35  test_expect_success "ipfs add succeeds" '
    36  	echo "Hello Worlds!" >mountdir/hello.txt &&
    37  	ipfs add mountdir/hello.txt >actual
    38  '
    39  
    40  test_expect_success "ipfs add output looks good" '
    41  	HASH="QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH" &&
    42  	echo "added $HASH hello.txt" >expected &&
    43  	test_cmp expected actual
    44  '
    45  
    46  test_expect_success "ipfs add --only-hash succeeds" '
    47  	ipfs add --only-hash mountdir/hello.txt > oh_actual
    48  '
    49  
    50  test_expect_success "ipfs add --only-hash output looks good" '
    51  	ipfs add --only-hash mountdir/hello.txt > oh_actual
    52  '
    53  
    54  test_expect_success "ipfs cat succeeds" '
    55  	ipfs cat "$HASH" >actual
    56  '
    57  
    58  test_expect_success "ipfs cat output looks good" '
    59  	echo "Hello Worlds!" >expected &&
    60  	test_cmp expected actual
    61  '
    62  
    63  test_expect_success "ipfs cat succeeds with stdin opened (issue #1141)" '
    64  	cat mountdir/hello.txt | while read line; do ipfs cat "$HASH" >actual || exit; done
    65  '
    66  
    67  test_expect_success "ipfs cat output looks good" '
    68  	test_cmp expected actual
    69  '
    70  
    71  test_expect_success "ipfs cat accept hash from stdin" '
    72  	echo "$HASH" | ipfs cat >actual
    73  '
    74  
    75  test_expect_success "ipfs cat output looks good" '
    76  	test_cmp expected actual
    77  '
    78  
    79  test_expect_success FUSE "cat ipfs/stuff succeeds" '
    80  	cat "ipfs/$HASH" >actual
    81  '
    82  
    83  test_expect_success FUSE "cat ipfs/stuff looks good" '
    84  	test_cmp expected actual
    85  '
    86  
    87  test_expect_success "'ipfs add -q' succeeds" '
    88  	echo "Hello Venus!" >mountdir/venus.txt &&
    89  	ipfs add -q mountdir/venus.txt >actual
    90  '
    91  
    92  test_expect_success "'ipfs add -q' output looks good" '
    93  	HASH="QmU5kp3BH3B8tnWUU2Pikdb2maksBNkb92FHRr56hyghh4" &&
    94  	echo "$HASH" >expected &&
    95  	test_cmp expected actual
    96  '
    97  
    98  test_expect_success "'ipfs add -q' with stdin input succeeds" '
    99  	echo "Hello Jupiter!" | ipfs add -q >actual
   100  '
   101  
   102  test_expect_success "'ipfs add -q' output looks good" '
   103  	HASH="QmUnvPcBctVTAcJpigv6KMqDvmDewksPWrNVoy1E1WP5fh" &&
   104  	echo "$HASH" >expected &&
   105  	test_cmp expected actual
   106  '
   107  
   108  test_expect_success "'ipfs cat' succeeds" '
   109  	ipfs cat "$HASH" >actual
   110  '
   111  
   112  test_expect_success "ipfs cat output looks good" '
   113  	echo "Hello Jupiter!" >expected &&
   114  	test_cmp expected actual
   115  '
   116  
   117  test_expect_success "'ipfs add' with stdin input succeeds" '
   118  	printf "Hello Neptune!\nHello Pluton!" | ipfs add >actual
   119  '
   120  
   121  test_expect_success "'ipfs add' output looks good" '
   122  	HASH="QmZDhWpi8NvKrekaYYhxKCdNVGWsFFe1CREnAjP1QbPaB3" &&
   123  	echo "added $HASH $HASH" >expected &&
   124  	test_cmp expected actual
   125  '
   126  
   127  test_expect_success "'ipfs cat' with stdin input succeeds" '
   128  	echo "$HASH" | ipfs cat >actual
   129  '
   130  
   131  test_expect_success "ipfs cat with stdin input output looks good" '
   132  	printf "Hello Neptune!\nHello Pluton!" >expected &&
   133  	test_cmp expected actual
   134  '
   135  
   136  test_expect_success "'ipfs add -r' succeeds" '
   137  	mkdir mountdir/planets &&
   138  	echo "Hello Mars!" >mountdir/planets/mars.txt &&
   139  	echo "Hello Venus!" >mountdir/planets/venus.txt &&
   140  	ipfs add -r mountdir/planets >actual
   141  '
   142  
   143  test_expect_success "'ipfs add -r' output looks good" '
   144  	PLANETS="QmWSgS32xQEcXMeqd3YPJLrNBLSdsfYCep2U7CFkyrjXwY" &&
   145  	MARS="QmPrrHqJzto9m7SyiRzarwkqPcCSsKR2EB1AyqJfe8L8tN" &&
   146  	VENUS="QmU5kp3BH3B8tnWUU2Pikdb2maksBNkb92FHRr56hyghh4" &&
   147  	echo "added $MARS planets/mars.txt" >expected &&
   148  	echo "added $VENUS planets/venus.txt" >>expected &&
   149  	echo "added $PLANETS planets" >>expected &&
   150  	test_cmp expected actual
   151  '
   152  
   153  test_expect_success "ipfs cat accept many hashes from stdin" '
   154  	{ echo "$MARS"; echo "$VENUS"; } | ipfs cat >actual
   155  '
   156  
   157  test_expect_success "ipfs cat output looks good" '
   158  	cat mountdir/planets/mars.txt mountdir/planets/venus.txt >expected &&
   159  	test_cmp expected actual
   160  '
   161  
   162  test_expect_success "ipfs cat accept many hashes as args" '
   163  	ipfs cat "$MARS" "$VENUS" >actual
   164  '
   165  
   166  test_expect_success "ipfs cat output looks good" '
   167  	test_cmp expected actual
   168  '
   169  
   170  test_expect_success "ipfs cat with both arg and stdin" '
   171  	echo "$MARS" | ipfs cat "$VENUS" >actual
   172  '
   173  
   174  test_expect_success "ipfs cat output looks good" '
   175  	cat mountdir/planets/venus.txt >expected &&
   176  	test_cmp expected actual
   177  '
   178  
   179  test_expect_success "ipfs cat with two args and stdin" '
   180  	echo "$MARS" | ipfs cat "$VENUS" "$VENUS" >actual
   181  '
   182  
   183  test_expect_success "ipfs cat output looks good" '
   184  	cat mountdir/planets/venus.txt mountdir/planets/venus.txt >expected &&
   185  	test_cmp expected actual
   186  '
   187  
   188  test_expect_success "go-random is installed" '
   189  	type random
   190  '
   191  
   192  test_expect_success "generate 5MB file using go-random" '
   193  	random 5242880 41 >mountdir/bigfile
   194  '
   195  
   196  test_expect_success "sha1 of the file looks ok" '
   197  	echo "11145620fb92eb5a49c9986b5c6844efda37e471660e" >sha1_expected &&
   198  	multihash -a=sha1 -e=hex mountdir/bigfile >sha1_actual &&
   199  	test_cmp sha1_expected sha1_actual
   200  '
   201  
   202  test_expect_success "'ipfs add bigfile' succeeds" '
   203  	ipfs add mountdir/bigfile >actual
   204  '
   205  
   206  test_expect_success "'ipfs add bigfile' output looks good" '
   207  	HASH="QmSr7FqYkxYWGoSfy8ZiaMWQ5vosb18DQGCzjwEQnVHkTb" &&
   208  	echo "added $HASH bigfile" >expected &&
   209  	test_cmp expected actual
   210  '
   211  test_expect_success "'ipfs cat' succeeds" '
   212  	ipfs cat "$HASH" >actual
   213  '
   214  
   215  test_expect_success "'ipfs cat' output looks good" '
   216  	test_cmp mountdir/bigfile actual
   217  '
   218  
   219  test_expect_success FUSE "cat ipfs/bigfile succeeds" '
   220  	cat "ipfs/$HASH" >actual
   221  '
   222  
   223  test_expect_success FUSE "cat ipfs/bigfile looks good" '
   224  	test_cmp mountdir/bigfile actual
   225  '
   226  
   227  test_expect_success EXPENSIVE "generate 100MB file using go-random" '
   228  	random 104857600 42 >mountdir/bigfile
   229  '
   230  
   231  test_expect_success EXPENSIVE "sha1 of the file looks ok" '
   232  	echo "1114885b197b01e0f7ff584458dc236cb9477d2e736d" >sha1_expected &&
   233  	multihash -a=sha1 -e=hex mountdir/bigfile >sha1_actual &&
   234  	test_cmp sha1_expected sha1_actual
   235  '
   236  
   237  test_expect_success EXPENSIVE "ipfs add bigfile succeeds" '
   238  	ipfs add mountdir/bigfile >actual
   239  '
   240  
   241  test_expect_success EXPENSIVE "ipfs add bigfile output looks good" '
   242  	HASH="QmU9SWAPPmNEKZB8umYMmjYvN7VyHqABNvdA6GUi4MMEz3" &&
   243  	echo "added $HASH bigfile" >expected &&
   244  	test_cmp expected actual
   245  '
   246  
   247  test_expect_success EXPENSIVE "ipfs cat succeeds" '
   248  	ipfs cat "$HASH" | multihash -a=sha1 -e=hex >sha1_actual
   249  '
   250  
   251  test_expect_success EXPENSIVE "ipfs cat output looks good" '
   252  	ipfs cat "$HASH" >actual &&
   253  	test_cmp mountdir/bigfile actual
   254  '
   255  
   256  test_expect_success EXPENSIVE "ipfs cat output hashed looks good" '
   257  	echo "1114885b197b01e0f7ff584458dc236cb9477d2e736d" >sha1_expected &&
   258  	test_cmp sha1_expected sha1_actual
   259  '
   260  
   261  test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile succeeds" '
   262  	cat "ipfs/$HASH" | multihash -a=sha1 -e=hex >sha1_actual
   263  '
   264  
   265  test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile looks good" '
   266  	test_cmp sha1_expected sha1_actual
   267  '
   268  
   269  test_expect_success "useful error message when adding a named pipe" '
   270  	mkfifo named-pipe &&
   271  	test_expect_code 1 ipfs add named-pipe 2>actual &&
   272      client_err "Error: Unrecognized file type for named-pipe: $(generic_stat named-pipe)" >expected &&
   273  	test_cmp expected actual
   274  '
   275  
   276  test_expect_success "useful error message when recursively adding a named pipe" '
   277  	mkdir named-pipe-dir &&
   278  	mkfifo named-pipe-dir/named-pipe &&
   279  	test_expect_code 1 ipfs add -r named-pipe-dir 2>actual &&
   280      printf "Error: Post http://127.0.0.1:$PORT_API/api/v0/add?encoding=json&progress=true&r=true&stream-channels=true: Unrecognized file type for named-pipe-dir/named-pipe: $(generic_stat named-pipe-dir/named-pipe)\n" >expected &&
   281  	test_cmp expected actual
   282  '
   283  
   284  test_kill_ipfs_daemon
   285  
   286  test_done