浏览代码

test: add test to unmarshal null into nil (#944)

Fixes #939
Chris Bannister 8 年之前
父节点
当前提交
00a10c8ee9
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      cassandra_test.go

+ 16 - 0
cassandra_test.go

@@ -665,6 +665,22 @@ func TestMapScanWithRefMap(t *testing.T) {
 	if testFullName.FirstName != "John" || testFullName.LastName != "Doe" {
 		t.Fatal("returned testfullname did not match")
 	}
+
+	// using MapScan to read a nil int value
+	intp := new(int64)
+	ret = map[string]interface{}{
+		"testint": &intp,
+	}
+	if err := session.Query("INSERT INTO scan_map_ref_table(testtext, testint) VALUES(?, ?)", "null-int", nil).Exec(); err != nil {
+		t.Fatal(err)
+	}
+	err := session.Query(`SELECT testint FROM scan_map_ref_table WHERE testtext = ?`, "null-int").MapScan(ret)
+	if err != nil {
+		t.Fatal(err)
+	} else if v := ret["testint"].(*int64); v != nil {
+		t.Fatalf("testint should be nil got %+#v", v)
+	}
+
 }
 
 func TestMapScan(t *testing.T) {