2023-08-12 14:03:08 +02:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-08-29 13:12:38 +02:00
|
|
|
"gopkg.in/yaml.v2"
|
2023-08-12 14:03:08 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestURLParseSuccess(t *testing.T) {
|
|
|
|
f := func(src string) {
|
|
|
|
t.Helper()
|
|
|
|
var u URL
|
|
|
|
if err := yaml.Unmarshal([]byte(src), &u); err != nil {
|
|
|
|
t.Fatalf("unexpected error for url: %s: %s", src, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f("http://some-url/path")
|
|
|
|
f("https://some-url/path")
|
|
|
|
f("socks5://some-url/path")
|
|
|
|
f("tls+socks5://some-sock-path")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseFail(t *testing.T) {
|
|
|
|
f := func(src string) {
|
|
|
|
t.Helper()
|
|
|
|
var u URL
|
|
|
|
if err := yaml.Unmarshal([]byte(src), &u); err == nil {
|
|
|
|
t.Fatalf("want error for url: %s", src)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f("bad-scheme://my-url")
|
|
|
|
f("unix://my-socket.sock")
|
|
|
|
f("http://some-url:bad-port")
|
|
|
|
}
|