diff --git a/core/commands/pubsub.go b/core/commands/pubsub.go index 4632e6fdf8c9..b45d657dca23 100644 --- a/core/commands/pubsub.go +++ b/core/commands/pubsub.go @@ -2,7 +2,6 @@ package commands import ( "context" - "encoding/binary" "fmt" "io" "io/ioutil" @@ -127,24 +126,15 @@ TOPIC ENCODING _, err = w.Write(dec) return err }), - // --enc=ndpayload is not documented, byt used internally by sharness tests + // DEPRECATED, undocumented format we used in tests, but not anymore + // \n\n "ndpayload": cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, psm *pubsubMessage) error { - _, dec, err := mbase.Decode(psm.Data) - if err != nil { - return err - } - data := append(dec, '\n') - _, err = w.Write(data) - return err + return errors.New("--enc=ndpayload was removed, use --enc=json instead") }), - // ¯\_(ツ)_/¯ – seems unused, can we remove this? + // DEPRECATED, uncodumented format we used in tests, but not anymore + // "lenpayload": cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, psm *pubsubMessage) error { - buf := make([]byte, 8, len(psm.Data)+8) - - n := binary.PutUvarint(buf, uint64(len(psm.Data))) - buf = append(buf[:n], psm.Data...) - _, err := w.Write(buf) - return err + return errors.New("--enc=lenpayload was removed, use --enc=json instead") }), }, Type: pubsubMessage{}, diff --git a/test/sharness/t0180-pubsub-gossipsub.sh b/test/sharness/t0180-pubsub-gossipsub.sh index c5ff8daf39e8..8c0686efd1e1 100755 --- a/test/sharness/t0180-pubsub-gossipsub.sh +++ b/test/sharness/t0180-pubsub-gossipsub.sh @@ -25,7 +25,7 @@ test_expect_success 'peer ids' ' ' test_expect_success 'pubsub' ' - echo "testOK" > expected && + echo -n "testOK" | ipfs multibase encode -b base64url > expected && touch empty && mkfifo wait || test_fsh echo init fail @@ -33,8 +33,8 @@ test_expect_success 'pubsub' ' # ipfs pubsub sub is long-running so we need to start it in the background and # wait put its output somewhere where we can access it ( - ipfsi 0 pubsub sub --enc=ndpayload testTopic | if read line; then - echo $line > actual && + ipfsi 0 pubsub sub --enc=json testTopic | if read line; then + echo $line | jq -j .data > actual && echo > wait fi ) & @@ -64,15 +64,15 @@ test_expect_success "wait until echo > wait executed" ' ' test_expect_success "wait for another pubsub message" ' - echo "testOK2" > expected && + echo -n "testOK2" | ipfs multibase encode -b base64url > expected && mkfifo wait2 || test_fsh echo init fail # ipfs pubsub sub is long-running so we need to start it in the background and # wait put its output somewhere where we can access it ( - ipfsi 2 pubsub sub --enc=ndpayload testTopic | if read line; then - echo $line > actual && + ipfsi 2 pubsub sub --enc=json testTopic | if read line; then + echo $line | jq -j .data > actual && echo > wait2 fi ) & @@ -83,11 +83,10 @@ test_expect_success "wait until ipfs pubsub sub is ready to do work" ' ' test_expect_success "publish something" ' - echo "testOK2" | ipfsi 1 pubsub pub testTopic &> pubErr + echo -n "testOK2" | ipfsi 1 pubsub pub testTopic &> pubErr ' test_expect_success "wait until echo > wait executed" ' - echo "testOK2" > expected && cat wait2 && test_cmp pubErr empty && test_cmp expected actual diff --git a/test/sharness/t0180-pubsub.sh b/test/sharness/t0180-pubsub.sh index 349e98d54c38..20d5f4c1c74b 100755 --- a/test/sharness/t0180-pubsub.sh +++ b/test/sharness/t0180-pubsub.sh @@ -22,7 +22,7 @@ run_pubsub_tests() { # ipfs pubsub sub test_expect_success 'pubsub' ' - echo "testOK" > expected && + echo -n "testOK" | ipfs multibase encode -b base64url > expected && touch empty && mkfifo wait || test_fsh echo init fail @@ -30,8 +30,8 @@ run_pubsub_tests() { # ipfs pubsub sub is long-running so we need to start it in the background and # wait put its output somewhere where we can access it ( - ipfsi 0 pubsub sub --enc=ndpayload testTopic | if read line; then - echo $line > actual && + ipfsi 0 pubsub sub --enc=json testTopic | if read line; then + echo $line | jq -j .data > actual && echo > wait fi ) & @@ -61,15 +61,15 @@ run_pubsub_tests() { ' test_expect_success "wait for another pubsub message" ' - echo "testOK2" > expected && + echo -n "testOK2" | ipfs multibase encode -b base64url > expected && mkfifo wait2 || test_fsh echo init fail # ipfs pubsub sub is long-running so we need to start it in the background and # wait put its output somewhere where we can access it ( - ipfsi 2 pubsub sub --enc=ndpayload testTopic | if read line; then - echo $line > actual && + ipfsi 2 pubsub sub --enc=json testTopic | if read line; then + echo $line | jq -j .data > actual && echo > wait2 fi ) & @@ -80,11 +80,10 @@ run_pubsub_tests() { ' test_expect_success "publish something" ' - echo "testOK2" | ipfsi 3 pubsub pub testTopic &> pubErr + echo -n "testOK2" | ipfsi 3 pubsub pub testTopic &> pubErr ' test_expect_success "wait until echo > wait executed" ' - echo "testOK2" > expected && cat wait2 && test_cmp pubErr empty && test_cmp expected actual @@ -114,7 +113,7 @@ startup_cluster $NUM_NODES --enable-pubsub-experiment test_expect_success 'set node 4 to listen on testTopic' ' rm -f node4_actual && - ipfsi 4 pubsub sub --enc=ndpayload testTopic > node4_actual & + ipfsi 4 pubsub sub --enc=json testTopic > node4_actual & ' run_pubsub_tests