VictoriaMetrics/lib/proxy/proxy_test.go
Nikolay 89fcb7baf0
lib/promscrape: adds validation for proxy_url scheme (#4823)
* lib/promscrape: adds validation for proxy_url scheme
adds tests
https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4811

* Update lib/proxy/proxy.go

* Update lib/proxy/proxy.go

---------

Co-authored-by: Aliaksandr Valialkin <valyala@victoriametrics.com>
2023-08-12 05:05:56 -07:00

34 lines
674 B
Go

package proxy
import (
"testing"
"gopkg.in/yaml.v3"
)
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")
}