2016-02-20 21:05:48 +00:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func parseURL(s string) *url.URL {
|
|
|
|
u, err := url.Parse(s)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return u
|
|
|
|
}
|
|
|
|
|
|
|
|
var configTests = []struct {
|
|
|
|
s string
|
|
|
|
cfg Config
|
|
|
|
}{
|
2018-03-15 20:37:18 +00:00
|
|
|
{
|
|
|
|
s: "rest:http://localhost:1234",
|
|
|
|
cfg: Config{
|
|
|
|
URL: parseURL("http://localhost:1234/"),
|
|
|
|
Connections: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
s: "rest:http://localhost:1234/",
|
|
|
|
cfg: Config{
|
|
|
|
URL: parseURL("http://localhost:1234/"),
|
|
|
|
Connections: 5,
|
|
|
|
},
|
|
|
|
},
|
2016-02-20 21:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseConfig(t *testing.T) {
|
2018-03-15 20:37:18 +00:00
|
|
|
for _, test := range configTests {
|
|
|
|
t.Run("", func(t *testing.T) {
|
|
|
|
cfg, err := ParseConfig(test.s)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%s failed: %v", test.s, err)
|
|
|
|
}
|
2016-02-20 21:05:48 +00:00
|
|
|
|
2018-03-15 20:37:18 +00:00
|
|
|
if !reflect.DeepEqual(cfg, test.cfg) {
|
|
|
|
t.Fatalf("\ninput: %s\n wrong config, want:\n %v\ngot:\n %v",
|
|
|
|
test.s, test.cfg, cfg)
|
|
|
|
}
|
|
|
|
})
|
2016-02-20 21:05:48 +00:00
|
|
|
}
|
|
|
|
}
|