@@ -2003,9 +2003,29 @@ func TestMarshalUDTMap(t *testing.T) {
20032003 "y" : 2 ,
20042004 "z" : 3 ,
20052005 }
2006- me := MarshalError (`marshal missing map key "x"` )
2007- if _ , err := Marshal (typeInfo , value ); err != me {
2008- t .Errorf ("got error %#v, want %#v" , err , me )
2006+ expected := []byte ("\xff \xff \xff \xff \x00 \x00 \x00 \x04 \x00 \x00 \x00 \x02 \x00 \x00 \x00 \x04 \x00 \x00 \x00 \x03 " )
2007+
2008+ data , err := Marshal (typeInfo , value )
2009+ if err != nil {
2010+ t .Errorf ("got error %#v" , err )
2011+ }
2012+ if ! bytes .Equal (data , expected ) {
2013+ t .Errorf ("got value %x" , data )
2014+ }
2015+ })
2016+ t .Run ("partially bound from the beginning" , func (t * testing.T ) {
2017+ value := map [string ]interface {}{
2018+ "x" : 1 ,
2019+ "y" : 2 ,
2020+ }
2021+ expected := []byte ("\x00 \x00 \x00 \x04 \x00 \x00 \x00 \x01 \x00 \x00 \x00 \x04 \x00 \x00 \x00 \x02 \xff \xff \xff \xff " )
2022+
2023+ data , err := Marshal (typeInfo , value )
2024+ if err != nil {
2025+ t .Errorf ("got error %#v" , err )
2026+ }
2027+ if ! bytes .Equal (data , expected ) {
2028+ t .Errorf ("got value %x" , data )
20092029 }
20102030 })
20112031 t .Run ("fully bound" , func (t * testing.T ) {
@@ -2021,7 +2041,76 @@ func TestMarshalUDTMap(t *testing.T) {
20212041 t .Errorf ("got error %#v" , err )
20222042 }
20232043 if ! bytes .Equal (data , expected ) {
2024- t .Errorf ("got error %x" , data )
2044+ t .Errorf ("got value %x" , data )
2045+ }
2046+ })
2047+ }
2048+
2049+ func TestMarshalUDTStruct (t * testing.T ) {
2050+ typeInfo := UDTTypeInfo {NativeType {proto : 3 , typ : TypeUDT }, "" , "xyz" , []UDTField {
2051+ {Name : "x" , Type : NativeType {proto : 3 , typ : TypeInt }},
2052+ {Name : "y" , Type : NativeType {proto : 3 , typ : TypeInt }},
2053+ {Name : "z" , Type : NativeType {proto : 3 , typ : TypeInt }},
2054+ }}
2055+
2056+ type xyzStruct struct {
2057+ X int32 `cql:"x"`
2058+ Y int32 `cql:"y"`
2059+ Z int32 `cql:"z"`
2060+ }
2061+ type xyStruct struct {
2062+ X int32 `cql:"x"`
2063+ Y int32 `cql:"y"`
2064+ }
2065+ type yzStruct struct {
2066+ Y int32 `cql:"y"`
2067+ Z int32 `cql:"z"`
2068+ }
2069+
2070+ t .Run ("partially bound" , func (t * testing.T ) {
2071+ value := yzStruct {
2072+ Y : 2 ,
2073+ Z : 3 ,
2074+ }
2075+ expected := []byte ("\xff \xff \xff \xff \x00 \x00 \x00 \x04 \x00 \x00 \x00 \x02 \x00 \x00 \x00 \x04 \x00 \x00 \x00 \x03 " )
2076+
2077+ data , err := Marshal (typeInfo , value )
2078+ if err != nil {
2079+ t .Errorf ("got error %#v" , err )
2080+ }
2081+ if ! bytes .Equal (data , expected ) {
2082+ t .Errorf ("got value %x" , data )
2083+ }
2084+ })
2085+ t .Run ("partially bound from the beginning" , func (t * testing.T ) {
2086+ value := xyStruct {
2087+ X : 1 ,
2088+ Y : 2 ,
2089+ }
2090+ expected := []byte ("\x00 \x00 \x00 \x04 \x00 \x00 \x00 \x01 \x00 \x00 \x00 \x04 \x00 \x00 \x00 \x02 \xff \xff \xff \xff " )
2091+
2092+ data , err := Marshal (typeInfo , value )
2093+ if err != nil {
2094+ t .Errorf ("got error %#v" , err )
2095+ }
2096+ if ! bytes .Equal (data , expected ) {
2097+ t .Errorf ("got value %x" , data )
2098+ }
2099+ })
2100+ t .Run ("fully bound" , func (t * testing.T ) {
2101+ value := xyzStruct {
2102+ X : 1 ,
2103+ Y : 2 ,
2104+ Z : 3 ,
2105+ }
2106+ expected := []byte ("\x00 \x00 \x00 \x04 \x00 \x00 \x00 \x01 \x00 \x00 \x00 \x04 \x00 \x00 \x00 \x02 \x00 \x00 \x00 \x04 \x00 \x00 \x00 \x03 " )
2107+
2108+ data , err := Marshal (typeInfo , value )
2109+ if err != nil {
2110+ t .Errorf ("got error %#v" , err )
2111+ }
2112+ if ! bytes .Equal (data , expected ) {
2113+ t .Errorf ("got value %x" , data )
20252114 }
20262115 })
20272116}
0 commit comments