github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/test/sharness/t0141-addfilter.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 ipfs swarm command"
     8  
     9  AF1="/ip4/192.168.0.0/ipcidr/16"
    10  AF2="/ip4/127.0.0.0/ipcidr/8"
    11  AF3="/ip6/2008:bcd::/ipcidr/32"
    12  AF4="/ip4/172.16.0.0/ipcidr/12"
    13  
    14  . lib/test-lib.sh
    15  
    16  test_init_ipfs
    17  
    18  test_swarm_filter_cmd() {
    19  	printf "" > list_expected
    20  	for AF in "$@"
    21  	do
    22  		echo "$AF" >>list_expected
    23  	done
    24  
    25  	test_expect_success "'ipfs swarm filters' succeeds" '
    26  		ipfs swarm filters > list_actual
    27  	'
    28  
    29  	test_expect_success "'ipfs swarm filters' output looks good" '
    30  		test_sort_cmp list_actual list_expected
    31  	'
    32  }
    33  
    34  test_swarm_filters() {
    35  
    36  	# expect first address from config
    37  	test_swarm_filter_cmd $AF1 $AF4
    38  
    39  	ipfs swarm filters rm all
    40  
    41  	test_swarm_filter_cmd
    42  
    43  	test_expect_success "'ipfs swarm filter add' succeeds" '
    44  		ipfs swarm filters add $AF1 $AF2 $AF3
    45  	'
    46  
    47  	test_swarm_filter_cmd $AF1 $AF2 $AF3
    48  
    49  	test_expect_success "'ipfs swarm filter rm' succeeds" '
    50  		ipfs swarm filters rm $AF2 $AF3
    51  	'
    52  
    53  	test_swarm_filter_cmd $AF1
    54  
    55  	test_expect_success "'ipfs swarm filter add' succeeds" '
    56  		ipfs swarm filters add $AF4 $AF2
    57  	'
    58  
    59  	test_swarm_filter_cmd $AF1 $AF2 $AF4
    60  
    61  	test_expect_success "'ipfs swarm filter rm' succeeds" '
    62  		ipfs swarm filters rm $AF1 $AF2 $AF4
    63  	'
    64  
    65  	test_swarm_filter_cmd
    66  }
    67  
    68  test_expect_success "init without any filters" '
    69  	echo "null" >expected &&
    70  	ipfs config Swarm.AddrFilters >actual &&
    71  	test_cmp expected actual
    72  '
    73  
    74  test_expect_success "adding addresses to the config to filter succeeds" '
    75  	ipfs config --json Swarm.AddrFilters "[\"$AF1\", \"$AF4\"]"
    76  '
    77  
    78  test_launch_ipfs_daemon
    79  
    80  test_swarm_filters
    81  
    82  test_kill_ipfs_daemon
    83  
    84  test_done