Skip to content

Commit

Permalink
add control func test
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Aug 23, 2024
1 parent e2e5372 commit 0b3010f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions sess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"testing"
"time"

"github.com/pkg/errors"
"golang.org/x/crypto/pbkdf2"
)

Expand Down Expand Up @@ -694,3 +695,37 @@ func TestReliability(t *testing.T) {
}
cli.Close()
}

func TestControl(t *testing.T) {
port := int(atomic.AddUint32(&baseport, 1))
block, _ := NewSalsa20BlockCrypt(pass)
l, err := ListenWithOptions(fmt.Sprintf("127.0.0.1:%v", port), block, 10, 1)
if err != nil {
panic(err)
}

errorA := errors.New("A")
err = l.Control(func(conn net.PacketConn) error {
fmt.Printf("Listener Control: conn: %v\n", conn)
return errorA
})

if err != errorA {
t.Fatal(err)
}

cli, err := dialEcho(port)
if err != nil {
panic(err)
}

errorB := errors.New("B")
err = cli.Control(func(conn net.PacketConn) error {
fmt.Printf("Client Control: conn: %v\n", conn)
return errorB
})

if err != errorB {
t.Fatal(err)
}
}

0 comments on commit 0b3010f

Please sign in to comment.