-
Notifications
You must be signed in to change notification settings - Fork 36
/
urlparams_test.go
67 lines (54 loc) · 1.84 KB
/
urlparams_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package gomaasapi_test
import (
"github.com/juju/gomaasapi/v2"
gc "gopkg.in/check.v1"
)
type urlParamsSuite struct {
}
var _ = gc.Suite(&urlParamsSuite{})
func (*urlParamsSuite) TestNewParamsNonNilValues(c *gc.C) {
params := gomaasapi.NewURLParams()
c.Assert(params.Values, gc.NotNil)
}
func (*urlParamsSuite) TestNewMaybeAddEmpty(c *gc.C) {
params := gomaasapi.NewURLParams()
params.MaybeAdd("foo", "")
c.Assert(params.Values.Encode(), gc.Equals, "")
}
func (*urlParamsSuite) TestNewMaybeAddWithValue(c *gc.C) {
params := gomaasapi.NewURLParams()
params.MaybeAdd("foo", "bar")
c.Assert(params.Values.Encode(), gc.Equals, "foo=bar")
}
func (*urlParamsSuite) TestNewMaybeAddIntZero(c *gc.C) {
params := gomaasapi.NewURLParams()
params.MaybeAddInt("foo", 0)
c.Assert(params.Values.Encode(), gc.Equals, "")
}
func (*urlParamsSuite) TestNewMaybeAddIntWithValue(c *gc.C) {
params := gomaasapi.NewURLParams()
params.MaybeAddInt("foo", 42)
c.Assert(params.Values.Encode(), gc.Equals, "foo=42")
}
func (*urlParamsSuite) TestNewMaybeAddBoolFalse(c *gc.C) {
params := gomaasapi.NewURLParams()
params.MaybeAddBool("foo", false)
c.Assert(params.Values.Encode(), gc.Equals, "")
}
func (*urlParamsSuite) TestNewMaybeAddBoolTrue(c *gc.C) {
params := gomaasapi.NewURLParams()
params.MaybeAddBool("foo", true)
c.Assert(params.Values.Encode(), gc.Equals, "foo=true")
}
func (*urlParamsSuite) TestNewMaybeAddManyNil(c *gc.C) {
params := gomaasapi.NewURLParams()
params.MaybeAddMany("foo", nil)
c.Assert(params.Values.Encode(), gc.Equals, "")
}
func (*urlParamsSuite) TestNewMaybeAddManyValues(c *gc.C) {
params := gomaasapi.NewURLParams()
params.MaybeAddMany("foo", []string{"two", "", "values"})
c.Assert(params.Values.Encode(), gc.Equals, "foo=two&foo=values")
}