mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 18:13:54 +08:00
Corenet API: Use simple util instead of socat for tests
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
@ -22,6 +22,10 @@ $(d)/go-timeout: test/dependencies/go-timeout
|
||||
$(go-build)
|
||||
TGTS_$(d) += $(d)/go-timeout
|
||||
|
||||
$(d)/ma-pipe-unidir: test/dependencies/ma-pipe-unidir
|
||||
$(go-build)
|
||||
TGTS_$(d) += $(d)/ma-pipe-unidir
|
||||
|
||||
TGTS_GX_$(d) := hang-fds iptb
|
||||
TGTS_GX_$(d) := $(addprefix $(d)/,$(TGTS_GX_$(d)))
|
||||
|
||||
|
22
test/dependencies/ma-pipe-unidir/LICENSE
Normal file
22
test/dependencies/ma-pipe-unidir/LICENSE
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Łukasz Magiera <magik6k@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
73
test/dependencies/ma-pipe-unidir/main.go
Normal file
73
test/dependencies/ma-pipe-unidir/main.go
Normal file
@ -0,0 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
manet "github.com/multiformats/go-multiaddr-net"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const USAGE = "ma-pipe-unidir [-l|--listen] [-h|--help] <send|recv> <multiaddr>\n"
|
||||
|
||||
type Opts struct {
|
||||
Listen bool
|
||||
}
|
||||
|
||||
func main() {
|
||||
opts := Opts{}
|
||||
flag.BoolVar(&opts.Listen, "l", false, "")
|
||||
flag.BoolVar(&opts.Listen, "listen", false, "")
|
||||
flag.Usage = func() {
|
||||
fmt.Print(USAGE)
|
||||
}
|
||||
flag.Parse()
|
||||
args := flag.Args()
|
||||
|
||||
if len(args) < 2 { // <mode> <addr>
|
||||
fmt.Print(USAGE)
|
||||
return
|
||||
}
|
||||
|
||||
mode := args[0]
|
||||
addr := args[1]
|
||||
|
||||
maddr, err := ma.NewMultiaddr(addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var conn manet.Conn
|
||||
|
||||
if opts.Listen {
|
||||
listener, err := manet.Listen(maddr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
conn, err = listener.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
conn, err = manet.Dial(maddr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
defer conn.Close()
|
||||
switch mode {
|
||||
case "recv":
|
||||
io.Copy(os.Stdout, conn)
|
||||
case "send":
|
||||
io.Copy(conn, os.Stdin)
|
||||
default:
|
||||
//TODO: a bit late
|
||||
fmt.Print(USAGE)
|
||||
return
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ T_$(d) = $(sort $(wildcard $(d)/t[0-9][0-9][0-9][0-9]-*.sh))
|
||||
|
||||
DEPS_$(d) := test/bin/random test/bin/multihash test/bin/pollEndpoint \
|
||||
test/bin/iptb test/bin/go-sleep test/bin/random-files \
|
||||
test/bin/go-timeout test/bin/hang-fds
|
||||
test/bin/go-timeout test/bin/hang-fds test/bin/ma-pipe-unidir
|
||||
DEPS_$(d) += cmd/ipfs/ipfs
|
||||
DEPS_$(d) += $(d)/clean-test-results
|
||||
DEPS_$(d) += $(SHARNESS_$(d))
|
||||
|
@ -21,11 +21,6 @@ test_expect_success 'peer ids' '
|
||||
PEERID_1=$(iptb get id 1)
|
||||
'
|
||||
|
||||
# netcat (nc) is needed for the following tests
|
||||
test_expect_success "socat is available" '
|
||||
type socat >/dev/null
|
||||
'
|
||||
|
||||
test_expect_success "test ports are closed" '
|
||||
(! (netstat -ln | grep "LISTEN" | grep ":10101 ")) &&
|
||||
(! (netstat -ln | grep "LISTEN" | grep ":10102 "))
|
||||
@ -36,22 +31,22 @@ test_expect_success 'start ipfs listener' '
|
||||
'
|
||||
|
||||
test_expect_success 'Test server to client communications' '
|
||||
socat FILE:corenet0.bin TCP-LISTEN:10101,reuseaddr &
|
||||
NC_SERVER_PID=$!
|
||||
ma-pipe-unidir --listen send /ip4/127.0.0.1/tcp/10101 < corenet0.bin &
|
||||
SERVER_PID=$!
|
||||
|
||||
ipfsi 1 exp corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
|
||||
socat TCP4:127.0.0.1:10102 OPEN:client.out,creat,trunc &&
|
||||
wait $NC_SERVER_PID
|
||||
ma-pipe-unidir recv /ip4/127.0.0.1/tcp/10102 > client.out &&
|
||||
wait $SERVER_PID
|
||||
'
|
||||
|
||||
test_expect_success 'Test server to client communications' '
|
||||
socat TCP-LISTEN:10101,reuseaddr OPEN:server.out,creat,trunc &
|
||||
NC_SERVER_PID=$!
|
||||
test_expect_success 'Test client to server communications' '
|
||||
ma-pipe-unidir --listen recv /ip4/127.0.0.1/tcp/10101 > server.out &
|
||||
SERVER_PID=$!
|
||||
#sleep 0.5 &&
|
||||
|
||||
ipfsi 1 exp corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
|
||||
socat FILE:corenet1.bin TCP4:127.0.0.1:10102 &&
|
||||
|
||||
wait $NC_SERVER_PID
|
||||
ma-pipe-unidir send /ip4/127.0.0.1/tcp/10102 < corenet1.bin
|
||||
wait $SERVER_PID
|
||||
'
|
||||
|
||||
test_expect_success 'server to client output looks good' '
|
||||
|
Reference in New Issue
Block a user