mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-01 14:47:38 +00:00
119bcedf17
* 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>
34 lines
674 B
Go
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")
|
|
}
|