|
@@ -29,12 +29,14 @@ import (
|
|
|
func TestV2KeysURLHelper(t *testing.T) {
|
|
func TestV2KeysURLHelper(t *testing.T) {
|
|
|
tests := []struct {
|
|
tests := []struct {
|
|
|
endpoint url.URL
|
|
endpoint url.URL
|
|
|
|
|
+ prefix string
|
|
|
key string
|
|
key string
|
|
|
want url.URL
|
|
want url.URL
|
|
|
}{
|
|
}{
|
|
|
// key is empty, no problem
|
|
// key is empty, no problem
|
|
|
{
|
|
{
|
|
|
endpoint: url.URL{Scheme: "http", Host: "example.com", Path: "/v2/keys"},
|
|
endpoint: url.URL{Scheme: "http", Host: "example.com", Path: "/v2/keys"},
|
|
|
|
|
+ prefix: "",
|
|
|
key: "",
|
|
key: "",
|
|
|
want: url.URL{Scheme: "http", Host: "example.com", Path: "/v2/keys"},
|
|
want: url.URL{Scheme: "http", Host: "example.com", Path: "/v2/keys"},
|
|
|
},
|
|
},
|
|
@@ -42,6 +44,7 @@ func TestV2KeysURLHelper(t *testing.T) {
|
|
|
// key is joined to path
|
|
// key is joined to path
|
|
|
{
|
|
{
|
|
|
endpoint: url.URL{Scheme: "http", Host: "example.com", Path: "/v2/keys"},
|
|
endpoint: url.URL{Scheme: "http", Host: "example.com", Path: "/v2/keys"},
|
|
|
|
|
+ prefix: "",
|
|
|
key: "/foo/bar",
|
|
key: "/foo/bar",
|
|
|
want: url.URL{Scheme: "http", Host: "example.com", Path: "/v2/keys/foo/bar"},
|
|
want: url.URL{Scheme: "http", Host: "example.com", Path: "/v2/keys/foo/bar"},
|
|
|
},
|
|
},
|
|
@@ -49,6 +52,7 @@ func TestV2KeysURLHelper(t *testing.T) {
|
|
|
// key is joined to path when path is empty
|
|
// key is joined to path when path is empty
|
|
|
{
|
|
{
|
|
|
endpoint: url.URL{Scheme: "http", Host: "example.com", Path: ""},
|
|
endpoint: url.URL{Scheme: "http", Host: "example.com", Path: ""},
|
|
|
|
|
+ prefix: "",
|
|
|
key: "/foo/bar",
|
|
key: "/foo/bar",
|
|
|
want: url.URL{Scheme: "http", Host: "example.com", Path: "/foo/bar"},
|
|
want: url.URL{Scheme: "http", Host: "example.com", Path: "/foo/bar"},
|
|
|
},
|
|
},
|
|
@@ -56,6 +60,7 @@ func TestV2KeysURLHelper(t *testing.T) {
|
|
|
// Host field carries through with port
|
|
// Host field carries through with port
|
|
|
{
|
|
{
|
|
|
endpoint: url.URL{Scheme: "http", Host: "example.com:8080", Path: "/v2/keys"},
|
|
endpoint: url.URL{Scheme: "http", Host: "example.com:8080", Path: "/v2/keys"},
|
|
|
|
|
+ prefix: "",
|
|
|
key: "",
|
|
key: "",
|
|
|
want: url.URL{Scheme: "http", Host: "example.com:8080", Path: "/v2/keys"},
|
|
want: url.URL{Scheme: "http", Host: "example.com:8080", Path: "/v2/keys"},
|
|
|
},
|
|
},
|
|
@@ -63,13 +68,21 @@ func TestV2KeysURLHelper(t *testing.T) {
|
|
|
// Scheme carries through
|
|
// Scheme carries through
|
|
|
{
|
|
{
|
|
|
endpoint: url.URL{Scheme: "https", Host: "example.com", Path: "/v2/keys"},
|
|
endpoint: url.URL{Scheme: "https", Host: "example.com", Path: "/v2/keys"},
|
|
|
|
|
+ prefix: "",
|
|
|
key: "",
|
|
key: "",
|
|
|
want: url.URL{Scheme: "https", Host: "example.com", Path: "/v2/keys"},
|
|
want: url.URL{Scheme: "https", Host: "example.com", Path: "/v2/keys"},
|
|
|
},
|
|
},
|
|
|
|
|
+ // Prefix is applied
|
|
|
|
|
+ {
|
|
|
|
|
+ endpoint: url.URL{Scheme: "https", Host: "example.com", Path: "/foo"},
|
|
|
|
|
+ prefix: "/bar",
|
|
|
|
|
+ key: "/baz",
|
|
|
|
|
+ want: url.URL{Scheme: "https", Host: "example.com", Path: "/foo/bar/baz"},
|
|
|
|
|
+ },
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
for i, tt := range tests {
|
|
|
- got := v2KeysURL(tt.endpoint, tt.key)
|
|
|
|
|
|
|
+ got := v2KeysURL(tt.endpoint, tt.prefix, tt.key)
|
|
|
if tt.want != *got {
|
|
if tt.want != *got {
|
|
|
t.Errorf("#%d: want=%#v, got=%#v", i, tt.want, *got)
|
|
t.Errorf("#%d: want=%#v, got=%#v", i, tt.want, *got)
|
|
|
}
|
|
}
|