blob: 112850dd4a69b43ad8b18a5adadcb12ec1e4e1b0 [file] [log] [blame]
Jon Perritt255b6f82014-09-30 16:07:50 -05001package gophercloud
2
3import (
4 "net/url"
5 "testing"
6
7 th "github.com/rackspace/gophercloud/testhelper"
8)
9
10func TestMaybeStringWithNonEmptyString(t *testing.T) {
11 testString := "carol"
12 expected := &testString
13 actual := MaybeString("carol")
14 th.CheckDeepEquals(t, actual, expected)
15}
16
17func TestMaybeStringWithEmptyString(t *testing.T) {
18 var expected *string
19 actual := MaybeString("")
20 th.CheckDeepEquals(t, actual, expected)
21}
22
23func TestBuildQueryStringWithPointerToStruct(t *testing.T) {
24 expected := &url.URL{
25 RawQuery: "j=2&r=red",
26 }
27
28 type Opts struct {
29 J int `q:"j"`
30 R string `q:"r"`
31 C bool
32 }
33
34 opts := Opts{J: 2, R: "red"}
35
36 actual, err := BuildQueryString(opts)
37 if err != nil {
38 t.Errorf("Error building query string: %v", err)
39 }
40
41 th.CheckDeepEquals(t, actual, expected)
42}