isZero unit tests
diff --git a/params_test.go b/params_test.go
index a9919d2..cb3b4d2 100644
--- a/params_test.go
+++ b/params_test.go
@@ -2,7 +2,9 @@
import (
"net/url"
+ "reflect"
"testing"
+ "time"
th "github.com/rackspace/gophercloud/testhelper"
)
@@ -11,24 +13,24 @@
testString := ""
var expected *string
actual := MaybeString(testString)
- th.CheckDeepEquals(t, actual, expected)
+ th.CheckDeepEquals(t, expected, actual)
testString = "carol"
expected = &testString
actual = MaybeString(testString)
- th.CheckDeepEquals(t, actual, expected)
+ th.CheckDeepEquals(t, expected, actual)
}
func TestMaybeInt(t *testing.T) {
testInt := 0
var expected *int
actual := MaybeInt(testInt)
- th.CheckDeepEquals(t, actual, expected)
+ th.CheckDeepEquals(t, expected, actual)
testInt = 4
expected = &testInt
actual = MaybeInt(testInt)
- th.CheckDeepEquals(t, actual, expected)
+ th.CheckDeepEquals(t, expected, actual)
}
func TestBuildQueryStringWithPointerToStruct(t *testing.T) {
@@ -49,7 +51,7 @@
t.Errorf("Error building query string: %v", err)
}
- th.CheckDeepEquals(t, actual, expected)
+ th.CheckDeepEquals(t, expected, actual)
}
func TestBuildQueryStringWithoutRequiredFieldSet(t *testing.T) {
@@ -68,3 +70,63 @@
t.Log(err)
}
+
+func TestBuildHeaders(t *testing.T) {
+ testStruct := struct {
+ Accept string `h:"Accept"`
+ Num int `h:"Number"`
+ Style bool `h:"Style"`
+ }{
+ Accept: "application/json",
+ Num: 4,
+ Style: true,
+ }
+ expected := map[string]string{"Accept": "application/json", "Number": "4", "Style": "true"}
+ actual, err := BuildHeaders(&testStruct)
+ th.CheckNoErr(t, err)
+ th.CheckDeepEquals(t, expected, actual)
+}
+
+func TestIsZero(t *testing.T) {
+ var testMap map[string]interface{}
+ testMapValue := reflect.ValueOf(testMap)
+ expected := true
+ actual := isZero(testMapValue)
+ th.CheckEquals(t, expected, actual)
+ testMap = map[string]interface{}{"empty": false}
+ testMapValue = reflect.ValueOf(testMap)
+ expected = false
+ actual = isZero(testMapValue)
+ th.CheckEquals(t, expected, actual)
+
+ var testArray [2]string
+ testArrayValue := reflect.ValueOf(testArray)
+ expected = true
+ actual = isZero(testArrayValue)
+ th.CheckEquals(t, expected, actual)
+ testArray = [2]string{"one", "two"}
+ testArrayValue = reflect.ValueOf(testArray)
+ expected = false
+ actual = isZero(testArrayValue)
+ th.CheckEquals(t, expected, actual)
+
+ var testStruct struct {
+ A string
+ B time.Time
+ }
+ testStructValue := reflect.ValueOf(testStruct)
+ expected = true
+ actual = isZero(testStructValue)
+ th.CheckEquals(t, expected, actual)
+ testStruct = struct {
+ A string
+ B time.Time
+ }{
+ B: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
+ }
+ testStructValue = reflect.ValueOf(testStruct)
+ expected = false
+ actual = isZero(testStructValue)
+ th.CheckEquals(t, expected, actual)
+
+}