diff options
author | Anjan Nath <kaludios@gmail.com> | 2022-06-12 00:14:38 +0530 |
---|---|---|
committer | Anjan Nath <kaludios@gmail.com> | 2022-06-12 23:10:11 +0530 |
commit | bb56d405ba531b447efa194e26e8218ab3f4a689 (patch) | |
tree | 68a80c03191b6c1431594bb7291cffbcd1665b30 | |
parent | d50d19ca2ed3d78909316a711060ed0be98555e0 (diff) |
add unit test to check panic in Dial and DialContext functions
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | dialer_test.go | 44 |
2 files changed, 48 insertions, 0 deletions
@@ -39,3 +39,7 @@ build-android: go get -u golang.org/x/mobile/cmd/gomobile $(GOMOBILE) init $(GOMOBILE) bind -x -target android -o mobile/android/obfsvpn.aar ./client/ + +test: + go test ./... + diff --git a/dialer_test.go b/dialer_test.go new file mode 100644 index 0000000..aa00a60 --- /dev/null +++ b/dialer_test.go @@ -0,0 +1,44 @@ +package obfsvpn + +import ( + "context" + "testing" +) + +const cert = "8nuAbPJwFrKc/29KcCfL5LBuEWxQrjBASYXdUbwcm9d9pKseGK4r2Tg47e23+t6WghxGGw" + +func TestDial(t *testing.T) { + defer func() { + if r := recover(); r != nil { + t.Error("Dial paniced") + } + }() + + dialer, err := NewDialerFromCert(cert) + if err != nil { + t.Errorf("Error creating client from cert: %v", err) + } + + _, err = dialer.Dial("tcp", "127.0.0.1:4430") + if err == nil { + t.Errorf("No Error in d.Dial when trying invalid address: %v", err) + } +} + +func TestDialContext(t *testing.T) { + defer func() { + if r := recover(); r != nil { + t.Error("DialContext paniced") + } + }() + + dialer, err := NewDialerFromCert(cert) + if err != nil { + t.Errorf("Error creating client from cert: %v", err) + } + + _, err = dialer.DialContext(context.Background(), "tcp", "127.0.0.1:4430") + if err == nil { + t.Errorf("No Error in d.Dial when trying invalid address: %v", err) + } +} |