launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #15022
[Merge] lp:~jtv/maas/gomaasapi-urljoin into lp:~maas-maintainers/maas/gomaasapi
Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/gomaasapi-urljoin into lp:~maas-maintainers/maas/gomaasapi.
Commit message:
Add helper: JoinURLs().
Requested reviews:
Raphaël Badin (rvb)
For more details, see:
https://code.launchpad.net/~jtv/maas/gomaasapi-urljoin/+merge/145131
--
https://code.launchpad.net/~jtv/maas/gomaasapi-urljoin/+merge/145131
Your team MAAS Maintainers is subscribed to branch lp:~maas-maintainers/maas/gomaasapi.
=== modified file 'templates/source_test.go'
--- templates/source_test.go 2013-01-24 05:21:29 +0000
+++ templates/source_test.go 2013-01-28 09:17:19 +0000
@@ -4,11 +4,10 @@
package gomaasapi
import (
- "launchpad.net/gocheck"
+ . "launchpad.net/gocheck"
)
-
// TODO: Replace with real test functions. Give them real names.
-func (suite *GomaasapiTestSuite) TestXXX(c *gocheck.C) {
- c.Check(2 + 2, gocheck.Equals, 4)
+func (suite *GomaasapiTestSuite) TestXXX(c *C) {
+ c.Check(2+2, Equals, 4)
}
=== added file 'util.go'
--- util.go 1970-01-01 00:00:00 +0000
+++ util.go 2013-01-28 09:17:19 +0000
@@ -0,0 +1,16 @@
+// Copyright 2013 Canonical Ltd. This software is licensed under the
+// GNU Lesser General Public License version 3 (see the file COPYING).
+
+package gomaasapi
+
+import (
+ "strings"
+)
+
+// Join a base URL and a subpath together.
+// Regardless of whether base_url ends in a trailing slash (or even multiple
+// trailing slashes), or whether there are any leading slashes at the begining
+// of path, the two will always be joined together by a single slash.
+func JoinURLs(base_url, path string) string {
+ return strings.TrimRight(base_url, "/") + "/" + strings.TrimLeft(path, "/")
+}
=== added file 'util_test.go'
--- util_test.go 1970-01-01 00:00:00 +0000
+++ util_test.go 2013-01-28 09:17:19 +0000
@@ -0,0 +1,20 @@
+// Copyright 2013 Canonical Ltd. This software is licensed under the
+// GNU Lesser General Public License version 3 (see the file COPYING).
+
+package gomaasapi
+
+import (
+ . "launchpad.net/gocheck"
+)
+
+func (suite *GomaasapiTestSuite) TestJoinURLsAppendsPathToBaseURL(c *C) {
+ c.Check(JoinURLs("http://example.com/", "foo"), Equals, "http://example.com/foo")
+}
+
+func (suite *GomaasapiTestSuite) TestJoinURLsAddsSlashIfNeeded(c *C) {
+ c.Check(JoinURLs("http://example.com/foo", "bar"), Equals, "http://example.com/foo/bar")
+}
+
+func (suite *GomaasapiTestSuite) TestJoinURLsNormalizesDoubleSlash(c *C) {
+ c.Check(JoinURLs("http://example.com/base/", "/szot"), Equals, "http://example.com/base/szot")
+}
Follow ups