Skip to content

Commit 0b3010f

Browse files
committed
add control func test
1 parent e2e5372 commit 0b3010f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

sess_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"testing"
3838
"time"
3939

40+
"github.com/pkg/errors"
4041
"golang.org/x/crypto/pbkdf2"
4142
)
4243

@@ -694,3 +695,37 @@ func TestReliability(t *testing.T) {
694695
}
695696
cli.Close()
696697
}
698+
699+
func TestControl(t *testing.T) {
700+
port := int(atomic.AddUint32(&baseport, 1))
701+
block, _ := NewSalsa20BlockCrypt(pass)
702+
l, err := ListenWithOptions(fmt.Sprintf("127.0.0.1:%v", port), block, 10, 1)
703+
if err != nil {
704+
panic(err)
705+
}
706+
707+
errorA := errors.New("A")
708+
err = l.Control(func(conn net.PacketConn) error {
709+
fmt.Printf("Listener Control: conn: %v\n", conn)
710+
return errorA
711+
})
712+
713+
if err != errorA {
714+
t.Fatal(err)
715+
}
716+
717+
cli, err := dialEcho(port)
718+
if err != nil {
719+
panic(err)
720+
}
721+
722+
errorB := errors.New("B")
723+
err = cli.Control(func(conn net.PacketConn) error {
724+
fmt.Printf("Client Control: conn: %v\n", conn)
725+
return errorB
726+
})
727+
728+
if err != errorB {
729+
t.Fatal(err)
730+
}
731+
}

0 commit comments

Comments
 (0)