aboutsummaryrefslogtreecommitdiffstats
path: root/bind_test.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2018-03-08 16:44:27 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2018-03-08 16:44:46 +0100
commit6cecaf31575d77d8f30be65a0a5d34055ee220a4 (patch)
tree4b2114afb2c19b59d7f03a752df7e37b842f5fe6 /bind_test.go
parentSupport nopi mode (diff)
downloadwireguard-go-6cecaf31575d77d8f30be65a0a5d34055ee220a4.tar.xz
wireguard-go-6cecaf31575d77d8f30be65a0a5d34055ee220a4.zip
Begin work on full device<->device unit-test
To simulate a full interaction between two WireGuard instances without networking, using dummy instances of the interfaces
Diffstat (limited to '')
-rw-r--r--bind_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/bind_test.go b/bind_test.go
new file mode 100644
index 0000000..41c4225
--- /dev/null
+++ b/bind_test.go
@@ -0,0 +1,50 @@
+package main
+
+import "errors"
+
+type DummyDatagram struct {
+ msg []byte
+ endpoint Endpoint
+ world bool // better type
+}
+
+type DummyBind struct {
+ in6 chan DummyDatagram
+ ou6 chan DummyDatagram
+ in4 chan DummyDatagram
+ ou4 chan DummyDatagram
+ closed bool
+}
+
+func (b *DummyBind) SetMark(v uint32) error {
+ return nil
+}
+
+func (b *DummyBind) ReceiveIPv6(buff []byte) (int, Endpoint, error) {
+ datagram, ok := <-b.in6
+ if !ok {
+ return 0, nil, errors.New("closed")
+ }
+ copy(buff, datagram.msg)
+ return len(datagram.msg), datagram.endpoint, nil
+}
+
+func (b *DummyBind) ReceiveIPv4(buff []byte) (int, Endpoint, error) {
+ datagram, ok := <-b.in4
+ if !ok {
+ return 0, nil, errors.New("closed")
+ }
+ copy(buff, datagram.msg)
+ return len(datagram.msg), datagram.endpoint, nil
+}
+
+func (b *DummyBind) Close() error {
+ close(b.in6)
+ close(b.in4)
+ b.closed = true
+ return nil
+}
+
+func (b *DummyBind) Send(buff []byte, end Endpoint) error {
+ return nil
+}