summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-05-30 17:08:37 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2024-05-30 17:08:47 +0200
commit3dcb85a9b9f3ef14d0bcad037ad66832dafe0eb6 (patch)
treed1dcb96163465327dfdfd36177457978b0bde036
parent39e81ffed381e14651cd1dd4f33b4036bce4a56d (diff)
Client Proxy: Add test
-rw-r--r--client/proxy_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/client/proxy_test.go b/client/proxy_test.go
new file mode 100644
index 0000000..ddb0c4f
--- /dev/null
+++ b/client/proxy_test.go
@@ -0,0 +1,36 @@
+package client
+
+import (
+ "context"
+ "errors"
+ "testing"
+
+ "codeberg.org/eduVPN/proxyguard"
+)
+
+func TestProxy(t *testing.T) {
+ // test race
+ p := Proxy{}
+ p.NewClient(&proxyguard.Client{})
+ go func() {
+ // connect to localhost will fail
+ // but we don't care about the error
+ _ = p.Tunnel(context.Background(), "127.0.0.1")
+ }()
+ // race!
+ _ = p.Cancel()
+
+ // cancel before tunneling
+ p.NewClient(&proxyguard.Client{})
+ if !errors.Is(p.Cancel(), ErrNoProxyGuardCancel) {
+ t.Fatalf("proxyguard cancel err not equal")
+ }
+ _ = p.Tunnel(context.Background(), "127.0.0.1")
+ p.Delete()
+
+ // tunnel without client
+ gerr := p.Tunnel(context.Background(), "127.0.0.1")
+ if !errors.Is(gerr, ErrNoProxyGuardClient) {
+ t.Fatalf("no proxyguard client err not equal")
+ }
+}