MCPcopy Create free account
hub / github.com/brimdata/super / TestMixedTypeArrayOfStructWithInterface

Function TestMixedTypeArrayOfStructWithInterface

sup/marshal_test.go:209–249  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

207}
208
209func TestMixedTypeArrayOfStructWithInterface(t *testing.T) {
210 t.Skip("see issue #4012")
211 input := []MessageThing{
212 {
213 Message: "hello",
214 Thing: &Plant{"red"},
215 },
216 {
217 Message: "world",
218 Thing: &Animal{"blue"},
219 },
220 }
221 m := sup.NewBSUPMarshaler()
222 m.Decorate(sup.StyleSimple)
223
224 zv, err := m.Marshal(input)
225 require.NoError(t, err)
226
227 var buffer bytes.Buffer
228 writer := bsupio.NewWriter(sio.NopCloser(&buffer))
229 recExpected := super.NewValue(zv.Type(), zv.Bytes())
230 writer.Write(recExpected)
231 writer.Close()
232
233 reader := bsupio.NewReader(super.NewContext(), &buffer)
234 defer reader.Close()
235 recActual, err := reader.Read()
236 require.NoError(t, err)
237 exp := sup.FormatValue(recExpected)
238 actual := sup.FormatValue(*recActual)
239 assert.Equal(t, exp, actual)
240 // Double check that all the proper typing made it into the implied union.
241 assert.Equal(t, `[{Message:"hello",Thing:{MyColor:"red"}::=Plant}::=MessageThing,{Message:"world",Thing:{MyColor:"blue"}::=Animal}::=MessageThing]`, actual)
242
243 u := sup.NewUnmarshaler()
244 u.Bind(Plant{}, Animal{}, MessageThing{})
245 var out RecordWithInterfaceSlice
246 err = u.Unmarshal(actual, &out)
247 require.NoError(t, err)
248 assert.Equal(t, input, out)
249}
250
251type Foo struct {
252 A int

Callers

nothing calls this directly

Calls 15

WriteMethod · 0.95
CloseMethod · 0.95
CloseMethod · 0.95
ReadMethod · 0.95
NewBSUPMarshalerFunction · 0.92
NewWriterFunction · 0.92
NopCloserFunction · 0.92
NewValueFunction · 0.92
NewReaderFunction · 0.92
NewContextFunction · 0.92
FormatValueFunction · 0.92
NewUnmarshalerFunction · 0.92

Tested by

no test coverage detected