summaryrefslogtreecommitdiffhomepage
path: root/endpoint_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 /endpoint_test.go
parentfd248c6cb1873229b5e487045accdf7ed7ac822e (diff)
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 'endpoint_test.go')
-rw-r--r--endpoint_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/endpoint_test.go b/endpoint_test.go
new file mode 100644
index 0000000..7021e48
--- /dev/null
+++ b/endpoint_test.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "math/rand"
+ "net"
+)
+
+type DummyEndpoint struct {
+ src [16]byte
+ dst [16]byte
+}
+
+func CreateDummyEndpoint() (*DummyEndpoint, error) {
+ var end DummyEndpoint
+ if _, err := rand.Read(end.src[:]); err != nil {
+ return nil, err
+ }
+ _, err := rand.Read(end.dst[:])
+ return &end, err
+}
+
+func (e *DummyEndpoint) ClearSrc() {}
+
+func (e *DummyEndpoint) SrcToString() string {
+ var addr net.UDPAddr
+ addr.IP = e.SrcIP()
+ addr.Port = 1000
+ return addr.String()
+}
+
+func (e *DummyEndpoint) DstToString() string {
+ var addr net.UDPAddr
+ addr.IP = e.DstIP()
+ addr.Port = 1000
+ return addr.String()
+}
+
+func (e *DummyEndpoint) SrcToBytes() []byte {
+ return e.src[:]
+}
+
+func (e *DummyEndpoint) DstIP() net.IP {
+ return e.dst[:]
+}
+
+func (e *DummyEndpoint) SrcIP() net.IP {
+ return e.src[:]
+}