launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #15121
[Merge] lp:~rvb/gomaasapi/gomaasapi-subobjectfix into lp:gomaasapi
Raphaël Badin has proposed merging lp:~rvb/gomaasapi/gomaasapi-subobjectfix into lp:gomaasapi.
Commit message:
Fix GetSubObject so that it can cope with absolute urls.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~rvb/gomaasapi/gomaasapi-subobjectfix/+merge/147156
This is required to be able to fetch an object given a gomaasapi.Client and its absolute url (from instance the instanceId which is the resource_uri of a node).
--
https://code.launchpad.net/~rvb/gomaasapi/gomaasapi-subobjectfix/+merge/147156
Your team MAAS Maintainers is requested to review the proposed merge of lp:~rvb/gomaasapi/gomaasapi-subobjectfix into lp:gomaasapi.
=== modified file 'maasobject.go'
--- maasobject.go 2013-02-06 03:54:20 +0000
+++ maasobject.go 2013-02-07 16:08:25 +0000
@@ -101,8 +101,13 @@
func (obj jsonMAASObject) GetSubObject(name string) MAASObject {
uri := obj.URI()
- uri.Path = EnsureTrailingSlash(JoinURLs(uri.Path, name))
- input := map[string]JSONObject{resourceURI: jsonString(uri.String())}
+ newUrl, err := url.Parse(name)
+ if err != nil {
+ panic(err)
+ }
+ resUrl := uri.ResolveReference(newUrl)
+ resUrl.Path = EnsureTrailingSlash(resUrl.Path)
+ input := map[string]JSONObject{resourceURI: jsonString(resUrl.String())}
return newJSONMAASObject(jsonMap(input), obj.client)
}
=== modified file 'maasobject_test.go'
--- maasobject_test.go 2013-02-06 08:40:48 +0000
+++ maasobject_test.go 2013-02-07 16:08:25 +0000
@@ -102,13 +102,13 @@
c.Check(URL, DeepEquals, resourceURL)
}
-func (suite *MAASObjectSuite) TestGetSubObject(c *C) {
+func (suite *MAASObjectSuite) TestGetSubObjectRelative(c *C) {
baseURL, _ := url.Parse("http://example.com/")
uri := "http://example.com/a/resource/"
input := map[string]JSONObject{resourceURI: jsonString(uri)}
client := Client{BaseURL: baseURL}
obj := newJSONMAASObject(jsonMap(input), client)
- subName := "/test"
+ subName := "test"
subObj := obj.GetSubObject(subName)
subURL := subObj.URL()
@@ -119,6 +119,21 @@
c.Check(subURL, DeepEquals, expectedSubURL)
}
+func (suite *MAASObjectSuite) TestGetSubObjectAbsolute(c *C) {
+ baseURL, _ := url.Parse("http://example.com/")
+ uri := "http://example.com/a/resource/"
+ input := map[string]JSONObject{resourceURI: jsonString(uri)}
+ client := Client{BaseURL: baseURL}
+ obj := newJSONMAASObject(jsonMap(input), client)
+ subName := "/b/test"
+
+ subObj := obj.GetSubObject(subName)
+ subURL := subObj.URL()
+
+ expectedSubURL, _ := url.Parse("http://example.com/b/test/")
+ c.Check(subURL, DeepEquals, expectedSubURL)
+}
+
func (suite *MAASObjectSuite) TestGetField(c *C) {
uri := "http://example.com/a/resource"
fieldName := "field name"
Follow ups