1
// Copyright 2012-2016 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENCE file for details.
9
jc "github.com/juju/testing/checkers"
10
gc "gopkg.in/check.v1"
13
func (suite *GomaasapiTestSuite) TestJoinURLsAppendsPathToBaseURL(c *gc.C) {
14
c.Check(JoinURLs("http://example.com/", "foo"), gc.Equals, "http://example.com/foo")
17
func (suite *GomaasapiTestSuite) TestJoinURLsAddsSlashIfNeeded(c *gc.C) {
18
c.Check(JoinURLs("http://example.com/foo", "bar"), gc.Equals, "http://example.com/foo/bar")
21
func (suite *GomaasapiTestSuite) TestJoinURLsNormalizesDoubleSlash(c *gc.C) {
22
c.Check(JoinURLs("http://example.com/base/", "/szot"), gc.Equals, "http://example.com/base/szot")
25
func (suite *GomaasapiTestSuite) TestEnsureTrailingSlashAppendsSlashIfMissing(c *gc.C) {
26
c.Check(EnsureTrailingSlash("test"), gc.Equals, "test/")
29
func (suite *GomaasapiTestSuite) TestEnsureTrailingSlashDoesNotAppendIfPresent(c *gc.C) {
30
c.Check(EnsureTrailingSlash("test/"), gc.Equals, "test/")
33
func (suite *GomaasapiTestSuite) TestEnsureTrailingSlashReturnsSlashIfEmpty(c *gc.C) {
34
c.Check(EnsureTrailingSlash(""), gc.Equals, "/")
37
func parseJSON(c *gc.C, source string) interface{} {
38
var parsed interface{}
39
err := json.Unmarshal([]byte(source), &parsed)
40
c.Assert(err, jc.ErrorIsNil)
44
func updateJSONMap(c *gc.C, source string, changes map[string]interface{}) string {
45
var parsed map[string]interface{}
46
err := json.Unmarshal([]byte(source), &parsed)
47
c.Assert(err, jc.ErrorIsNil)
48
for key, value := range changes {
51
bytes, err := json.Marshal(parsed)
52
c.Assert(err, jc.ErrorIsNil)