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

     1  #!/bin/sh
     2  
     3  test_description="Test config command"
     4  
     5  . lib/test-lib.sh
     6  
     7  # we use a function so that we can run it both offline + online
     8  test_config_cmd_set() {
     9  
    10    # flags (like --bool in "ipfs config --bool")
    11    cfg_flags="" # unset in case.
    12    test "$#" = 3 && { cfg_flags=$1; shift; }
    13  
    14    cfg_key=$1
    15    cfg_val=$2
    16    test_expect_success "ipfs config succeeds" '
    17      ipfs config $cfg_flags "$cfg_key" "$cfg_val"
    18    '
    19  
    20    test_expect_success "ipfs config output looks good" '
    21      echo "$cfg_val" >expected &&
    22      ipfs config "$cfg_key" >actual &&
    23      test_cmp expected actual
    24    '
    25  
    26    # also test our lib function. it should work too.
    27    cfg_key="Lib.$cfg_key"
    28    test_expect_success "test_config_set succeeds" '
    29      test_config_set $cfg_flags "$cfg_key" "$cfg_val"
    30    '
    31  
    32    test_expect_success "test_config_set value looks good" '
    33      echo "$cfg_val" >expected &&
    34      ipfs config "$cfg_key" >actual &&
    35      test_cmp expected actual
    36    '
    37  }
    38  
    39  # this is a bit brittle. the problem is we need to test
    40  # with something that will be forced to unmarshal as a struct.
    41  # (i.e. just setting 'ipfs config --json foo "[1, 2, 3]"') may
    42  # set it as astring instead of proper json. We leverage the
    43  # unmarshalling that has to happen.
    44  CONFIG_SET_JSON_TEST='{
    45    "MDNS": {
    46      "Enabled": true,
    47      "Interval": 10
    48    }
    49  }'
    50  
    51  test_config_cmd() {
    52    test_config_cmd_set "beep" "boop"
    53    test_config_cmd_set "beep1" "boop2"
    54    test_config_cmd_set "beep1" "boop2"
    55    test_config_cmd_set "--bool" "beep2" "true"
    56    test_config_cmd_set "--bool" "beep2" "false"
    57    test_config_cmd_set "--json" "beep3" "true"
    58    test_config_cmd_set "--json" "beep3" "false"
    59    test_config_cmd_set "--json" "Discovery" "$CONFIG_SET_JSON_TEST"
    60    test_config_cmd_set "--json" "deep-not-defined.prop" "true"
    61    test_config_cmd_set "--json" "deep-null" "null"
    62    test_config_cmd_set "--json" "deep-null.prop" "true"
    63  
    64  }
    65  
    66  test_init_ipfs
    67  
    68  # should work offline
    69  test_config_cmd
    70  
    71  # should work online
    72  test_launch_ipfs_daemon
    73  test_config_cmd
    74  test_kill_ipfs_daemon
    75  
    76  
    77  test_done