WireGuard / wgctrl-go

Package wgctrl enables control of WireGuard interfaces on multiple platforms.
https://godoc.org/golang.zx2c4.com/wireguard/wgctrl
MIT License
730 stars 85 forks source link

internal/wguser: refactoring to enable integration tests on Windows #45

Closed mdlayher closed 5 years ago

mdlayher commented 5 years ago

Windows output:

matt@DESKTOP-2G8V6U5 C:\Users\matt\wgctrl-go>go test -v -count 1 ./internal/wguser
=== RUN   TestClientDevice
=== RUN   TestClientDevice/not_found
=== RUN   TestClientDevice/ok
--- PASS: TestClientDevice (0.01s)
    --- PASS: TestClientDevice/not_found (0.00s)
        client_test.go:42: userspace device: \\.\pipe\wguser-test501575300\wgtest0
    --- PASS: TestClientDevice/ok (0.01s)
        client_test.go:42: userspace device: \\.\pipe\wguser-test501575300\wgtest0
=== RUN   TestClientConfigureDeviceError
=== RUN   TestClientConfigureDeviceError/not_found
=== RUN   TestClientConfigureDeviceError/bad_errno
--- PASS: TestClientConfigureDeviceError (0.00s)
    --- PASS: TestClientConfigureDeviceError/not_found (0.00s)
        configure_test.go:62: userspace device: \\.\pipe\wguser-test506874100\wgtest0
    --- PASS: TestClientConfigureDeviceError/bad_errno (0.00s)
        configure_test.go:62: userspace device: \\.\pipe\wguser-test507943400\wgtest0
=== RUN   TestClientConfigureDeviceOK
=== RUN   TestClientConfigureDeviceOK/ok,_none
=== RUN   TestClientConfigureDeviceOK/ok,_clear_key
=== RUN   TestClientConfigureDeviceOK/ok,_all
--- PASS: TestClientConfigureDeviceOK (0.01s)
    --- PASS: TestClientConfigureDeviceOK/ok,_none (0.00s)
        configure_test.go:144: userspace device: \\.\pipe\wguser-test511675000\wgtest0
    --- PASS: TestClientConfigureDeviceOK/ok,_clear_key (0.00s)
        configure_test.go:144: userspace device: \\.\pipe\wguser-test515279700\wgtest0
    --- PASS: TestClientConfigureDeviceOK/ok,_all (0.00s)
        configure_test.go:144: userspace device: \\.\pipe\wguser-test517315700\wgtest0
=== RUN   TestClientDevices
=== RUN   TestClientDevices/invalid_key=value
=== RUN   TestClientDevices/invalid_public_key
=== RUN   TestClientDevices/short_public_key
=== RUN   TestClientDevices/invalid_fwmark
=== RUN   TestClientDevices/invalid_endpoint
=== RUN   TestClientDevices/invalid_allowed_ip
=== RUN   TestClientDevices/error
=== RUN   TestClientDevices/ok
--- PASS: TestClientDevices (0.03s)
    --- PASS: TestClientDevices/invalid_key=value (0.01s)
        parse_test.go:156: userspace device: \\.\pipe\wguser-test521340700\wgtest0
    --- PASS: TestClientDevices/invalid_public_key (0.00s)
        parse_test.go:156: userspace device: \\.\pipe\wguser-test527939100\wgtest0
    --- PASS: TestClientDevices/short_public_key (0.00s)
        parse_test.go:156: userspace device: \\.\pipe\wguser-test530979400\wgtest0
    --- PASS: TestClientDevices/invalid_fwmark (0.00s)
        parse_test.go:156: userspace device: \\.\pipe\wguser-test534021100\wgtest0
    --- PASS: TestClientDevices/invalid_endpoint (0.00s)
        parse_test.go:156: userspace device: \\.\pipe\wguser-test538048700\wgtest0
    --- PASS: TestClientDevices/invalid_allowed_ip (0.00s)
        parse_test.go:156: userspace device: \\.\pipe\wguser-test541068200\wgtest0
    --- PASS: TestClientDevices/error (0.00s)
        parse_test.go:156: userspace device: \\.\pipe\wguser-test543684700\wgtest0
    --- PASS: TestClientDevices/ok (0.00s)
        parse_test.go:156: userspace device: \\.\pipe\wguser-test546727100\wgtest0
PASS
ok      golang.zx2c4.com/wireguard/wgctrl/internal/wguser       0.476s

See the CI build for WINE output, where these tests are skipped due to WINE apparently not supporting named pipe accept calls. The output from my machine before skipping:

panic: failed to accept connection: Call not implemented.                                 

goroutine 19 [running]:                                                                                         
golang.zx2c4.com/wireguard/wgctrl/internal/wguser.panicf(...)                                   
        /home/matt/src/golang.zx2c4.com/wireguard/wgctrl/internal/wguser/client.go:98         
golang.zx2c4.com/wireguard/wgctrl/internal/wguser.testClient.func1(0xc0000ec0e0, 0x66dac0, 0xc00010c000, 0xc0000ec0c8, 0xc000100120
, 0xc0000ec0d0, 0x9, 0x9)                                                                       
        /home/matt/src/golang.zx2c4.com/wireguard/wgctrl/internal/wguser/client_test.go:90 +0x41d
created by golang.zx2c4.com/wireguard/wgctrl/internal/wguser.testClient                         
        /home/matt/src/golang.zx2c4.com/wireguard/wgctrl/internal/wguser/client_test.go:81 +0x289