forked from bitcoin-sv/spv-wallet-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_options_test.go
33 lines (30 loc) · 1 KB
/
client_options_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package walletclient
import "testing"
func TestValidateAndCleanURL(t *testing.T) {
tests := []struct {
name string
rawURL string
expected string
wantErr bool
}{
{"Empty URL", "", "", true},
{"Valid URL with path", "http://example.com/path", "http://example.com", false},
{"Valid URL without path", "http://example.com", "http://example.com", false},
{"Valid URL with port", "http://example.com:8080", "http://example.com:8080", false},
{"Invalid URL", "http://%41:8080/", "", true},
{"HTTPS URL", "https://example.com", "https://example.com", false},
{"HTTPS URL with path", "https://example.com/path", "https://example.com", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := validateAndCleanURL(tt.rawURL)
if (err != nil) != tt.wantErr {
t.Errorf("validateAndCleanURL() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.expected {
t.Errorf("validateAndCleanURL() = %v, expected %v", got, tt.expected)
}
})
}
}