Jon Perritt | 255b6f8 | 2014-09-30 16:07:50 -0500 | [diff] [blame^] | 1 | package gophercloud |
| 2 | |
| 3 | import ( |
| 4 | "net/url" |
| 5 | "testing" |
| 6 | |
| 7 | th "github.com/rackspace/gophercloud/testhelper" |
| 8 | ) |
| 9 | |
| 10 | func TestMaybeStringWithNonEmptyString(t *testing.T) { |
| 11 | testString := "carol" |
| 12 | expected := &testString |
| 13 | actual := MaybeString("carol") |
| 14 | th.CheckDeepEquals(t, actual, expected) |
| 15 | } |
| 16 | |
| 17 | func TestMaybeStringWithEmptyString(t *testing.T) { |
| 18 | var expected *string |
| 19 | actual := MaybeString("") |
| 20 | th.CheckDeepEquals(t, actual, expected) |
| 21 | } |
| 22 | |
| 23 | func 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 | } |