launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #15139
[Merge] lp:~rvb/gomaasapi/add-trailing-slash into lp:gomaasapi
Raphaël Badin has proposed merging lp:~rvb/gomaasapi/add-trailing-slash into lp:gomaasapi with lp:~jtv/gomaasapi/single-wrapper-class as a prerequisite.
Commit message:
Ensure the given API URL has a trailing slash when creating client objects.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~rvb/gomaasapi/add-trailing-slash/+merge/147666
The reasoning behind this change is that people should not have to worry about making sure the API URL they provide ends with a slash. gomaasapi should add a trailing slash if it's missing.
--
https://code.launchpad.net/~rvb/gomaasapi/add-trailing-slash/+merge/147666
Your team MAAS Maintainers is requested to review the proposed merge of lp:~rvb/gomaasapi/add-trailing-slash into lp:gomaasapi.
=== modified file 'client.go'
--- client.go 2013-02-11 14:15:27 +0000
+++ client.go 2013-02-11 14:15:27 +0000
@@ -117,6 +117,7 @@
// NewAnonymousClient creates a client that issues anonymous requests.
func NewAnonymousClient(BaseURL string) (*Client, error) {
+ BaseURL = EnsureTrailingSlash(BaseURL)
parsedBaseURL, err := url.Parse(BaseURL)
if err != nil {
return nil, err
@@ -128,6 +129,7 @@
// OAuth tokens and creates an Client that will use these tokens to sign the
// requests it issues.
func NewAuthenticatedClient(BaseURL string, apiKey string) (*Client, error) {
+ BaseURL = EnsureTrailingSlash(BaseURL)
elements := strings.Split(apiKey, ":")
if len(elements) != 3 {
errString := "invalid API key %q; expected \"<consumer secret>:<token key>:<token secret>\""
=== modified file 'client_test.go'
--- client_test.go 2013-02-05 14:39:14 +0000
+++ client_test.go 2013-02-11 14:15:27 +0000
@@ -115,6 +115,20 @@
c.Check(err, IsNil)
}
+func (suite *ClientSuite) TestNewAnonymousClientEnsuresTrailingSlash(c *C) {
+ client, err := NewAnonymousClient("http://example.com/api/1.0")
+ c.Check(err, IsNil)
+ expectedURL, _ := url.Parse("http://example.com/api/1.0/")
+ c.Check(client.BaseURL, DeepEquals, expectedURL)
+}
+
+func (suite *ClientSuite) TestNewAuthenticatedClientEnsuresTrailingSlash(c *C) {
+ client, err := NewAuthenticatedClient("http://example.com/api/1.0", "a:b:c")
+ c.Check(err, IsNil)
+ expectedURL, _ := url.Parse("http://example.com/api/1.0/")
+ c.Check(client.BaseURL, DeepEquals, expectedURL)
+}
+
func (suite *ClientSuite) TestNewAuthenticatedClientParsesApiKey(c *C) {
// NewAuthenticatedClient returns a plainTextOAuthSigneri configured
// to use the given API key.