|
@@ -6,29 +6,49 @@ import (
|
|
|
"testing"
|
|
"testing"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-func TestNewDirectorEndpointValidation(t *testing.T) {
|
|
|
|
|
|
|
+func TestNewDirectorScheme(t *testing.T) {
|
|
|
tests := []struct {
|
|
tests := []struct {
|
|
|
- good bool
|
|
|
|
|
- endpoints []string
|
|
|
|
|
|
|
+ scheme string
|
|
|
|
|
+ addrs []string
|
|
|
|
|
+ want []string
|
|
|
}{
|
|
}{
|
|
|
- {true, []string{"http://192.0.2.8"}},
|
|
|
|
|
- {true, []string{"http://192.0.2.8:8001"}},
|
|
|
|
|
- {true, []string{"http://example.com"}},
|
|
|
|
|
- {true, []string{"http://example.com:8001"}},
|
|
|
|
|
- {true, []string{"http://192.0.2.8:8001", "http://example.com:8002"}},
|
|
|
|
|
-
|
|
|
|
|
- {false, []string{"://"}},
|
|
|
|
|
- {false, []string{"http://"}},
|
|
|
|
|
- {false, []string{"192.0.2.8"}},
|
|
|
|
|
- {false, []string{"192.0.2.8:8001"}},
|
|
|
|
|
- {false, []string{""}},
|
|
|
|
|
- {false, []string{}},
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ scheme: "http",
|
|
|
|
|
+ addrs: []string{"192.0.2.8:4002", "example.com:8080"},
|
|
|
|
|
+ want: []string{"http://192.0.2.8:4002", "http://example.com:8080"},
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ scheme: "https",
|
|
|
|
|
+ addrs: []string{"192.0.2.8:4002", "example.com:8080"},
|
|
|
|
|
+ want: []string{"https://192.0.2.8:4002", "https://example.com:8080"},
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // accept addrs without a port
|
|
|
|
|
+ {
|
|
|
|
|
+ scheme: "http",
|
|
|
|
|
+ addrs: []string{"192.0.2.8"},
|
|
|
|
|
+ want: []string{"http://192.0.2.8"},
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // accept addrs even if they are garbage
|
|
|
|
|
+ {
|
|
|
|
|
+ scheme: "http",
|
|
|
|
|
+ addrs: []string{"."},
|
|
|
|
|
+ want: []string{"http://."},
|
|
|
|
|
+ },
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
for i, tt := range tests {
|
|
|
- _, err := newDirector(tt.endpoints)
|
|
|
|
|
- if tt.good != (err == nil) {
|
|
|
|
|
- t.Errorf("#%d: expected success = %t, got err = %v", i, tt.good, err)
|
|
|
|
|
|
|
+ got, err := newDirector(tt.scheme, tt.addrs)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ t.Errorf("#%d: newDirectory returned unexpected error: %v", i, err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for ii, wep := range tt.want {
|
|
|
|
|
+ gep := got.ep[ii].URL.String()
|
|
|
|
|
+ if !reflect.DeepEqual(wep, gep) {
|
|
|
|
|
+ t.Errorf("#%d: want endpoints[%d] = %#v, got = %#v", i, ii, wep, gep)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|