|
1 |
| -//+build all unit |
| 1 | +//go:build all || unit |
| 2 | +// +build all unit |
2 | 3 |
|
3 | 4 | package gocql
|
4 | 5 |
|
@@ -1939,6 +1940,41 @@ func TestUnmarshalTuple(t *testing.T) {
|
1939 | 1940 | })
|
1940 | 1941 | }
|
1941 | 1942 |
|
| 1943 | +func TestMarshalUDTMap(t *testing.T) { |
| 1944 | + typeInfo := UDTTypeInfo{NativeType{proto: 3, typ: TypeUDT}, "", "xyz", []UDTField{ |
| 1945 | + {Name: "x", Type: NativeType{proto: 3, typ: TypeInt}}, |
| 1946 | + {Name: "y", Type: NativeType{proto: 3, typ: TypeInt}}, |
| 1947 | + {Name: "z", Type: NativeType{proto: 3, typ: TypeInt}}, |
| 1948 | + }} |
| 1949 | + |
| 1950 | + t.Run("partially bound", func(t *testing.T) { |
| 1951 | + value := map[string]interface{}{ |
| 1952 | + "y": 2, |
| 1953 | + "z": 3, |
| 1954 | + } |
| 1955 | + me := MarshalError(`marshal missing map key "x"`) |
| 1956 | + if _, err := Marshal(typeInfo, value); err != me { |
| 1957 | + t.Errorf("got error %#v, want %#v", err, me) |
| 1958 | + } |
| 1959 | + }) |
| 1960 | + t.Run("fully bound", func(t *testing.T) { |
| 1961 | + value := map[string]interface{}{ |
| 1962 | + "x": 1, |
| 1963 | + "y": 2, |
| 1964 | + "z": 3, |
| 1965 | + } |
| 1966 | + 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") |
| 1967 | + |
| 1968 | + data, err := Marshal(typeInfo, value) |
| 1969 | + if err != nil { |
| 1970 | + t.Errorf("got error %#v", err) |
| 1971 | + } |
| 1972 | + if !bytes.Equal(data, expected) { |
| 1973 | + t.Errorf("got error %x", data) |
| 1974 | + } |
| 1975 | + }) |
| 1976 | +} |
| 1977 | + |
1942 | 1978 | func TestMarshalNil(t *testing.T) {
|
1943 | 1979 | types := []Type{
|
1944 | 1980 | TypeAscii,
|
|
0 commit comments