remote: Test HTTP validation

This commit is contained in:
Armon Dadgar 2014-12-04 16:56:55 -08:00 committed by Mitchell Hashimoto
parent 02d8df93e4
commit c1ecdd1e3d
2 changed files with 20 additions and 0 deletions

View File

@ -34,6 +34,9 @@ func (c *HTTPRemoteClient) validateConfig(conf map[string]string) error {
if err != nil {
return fmt.Errorf("failed to parse url: %v", err)
}
if url.Scheme != "http" && url.Scheme != "https" {
return fmt.Errorf("invalid url: %s", url)
}
c.url = url
return nil
}

View File

@ -19,6 +19,23 @@ func TestHTTPRemote_Interface(t *testing.T) {
}
}
func TestHTTPRemote_Validate(t *testing.T) {
conf := map[string]string{}
if _, err := NewHTTPRemoteClient(conf); err == nil {
t.Fatalf("expect error")
}
conf["url"] = ""
if _, err := NewHTTPRemoteClient(conf); err == nil {
t.Fatalf("expect error")
}
conf["url"] = "http://cool.com"
if _, err := NewHTTPRemoteClient(conf); err != nil {
t.Fatalf("err: %v", err)
}
}
func TestHTTPRemote_GetState(t *testing.T) {
type tcase struct {
Code int