Support SubResource call on Request

Allows better semantic use of Request when dealing with sub resources,
and allows clients to ignore ordering.  Supports multiple segments because
sub-resources are less tightly structured than regular resources.
This commit is contained in:
Clayton Coleman
2015-03-08 23:52:53 -04:00
parent 4b16a87096
commit 227a1d306d
2 changed files with 31 additions and 2 deletions

View File

@@ -129,6 +129,16 @@ func TestRequestOrdersNamespaceInPath(t *testing.T) {
}
}
func TestRequestOrdersSubResource(t *testing.T) {
r := (&Request{
baseURL: &url.URL{},
path: "/test/",
}).Name("bar").Resource("baz").Namespace("foo").Suffix("test").SubResource("a", "b")
if s := r.finalURL(); s != "/test/namespaces/foo/baz/bar/a/b/test" {
t.Errorf("namespace should be in order in path: %s", s)
}
}
func TestRequestSetTwiceError(t *testing.T) {
if (&Request{}).Name("bar").Name("baz").err == nil {
t.Errorf("setting name twice should result in error")
@@ -139,6 +149,9 @@ func TestRequestSetTwiceError(t *testing.T) {
if (&Request{}).Resource("bar").Resource("baz").err == nil {
t.Errorf("setting resource twice should result in error")
}
if (&Request{}).SubResource("bar").SubResource("baz").err == nil {
t.Errorf("setting subresource twice should result in error")
}
}
func TestRequestParseSelectorParam(t *testing.T) {