MCPcopy Create free account
hub / github.com/francoispqt/gojay / TestEncoderObjectEncodeAPIError

Function TestEncoderObjectEncodeAPIError

encode_object_test.go:396–430  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

394}
395
396func TestEncoderObjectEncodeAPIError(t *testing.T) {
397 t.Run("interface-key-error", func(t *testing.T) {
398 builder := &strings.Builder{}
399 enc := NewEncoder(builder)
400 err := enc.EncodeObject(&testObjectWithUnknownType{struct{}{}})
401 assert.NotNil(t, err, "Error should not be nil")
402 assert.Equal(t, "Invalid type struct {} provided to Marshal", err.Error(), "err.Error() should be 'Invalid type struct {} provided to Marshal'")
403 })
404 t.Run("write-error", func(t *testing.T) {
405 w := TestWriterError("")
406 enc := NewEncoder(w)
407 err := enc.EncodeObject(&testObject{})
408 assert.NotNil(t, err, "Error should not be nil")
409 assert.Equal(t, "Test Error", err.Error(), "err.Error() should be 'Test Error'")
410 })
411 t.Run("interface-error", func(t *testing.T) {
412 builder := &strings.Builder{}
413 enc := NewEncoder(builder)
414 enc.AddInterfaceKeyOmitEmpty("test", struct{}{})
415 assert.NotNil(t, enc.err, "enc.Err() should not be nil")
416 })
417 t.Run("pool-error", func(t *testing.T) {
418 v := &TestEncoding{}
419 enc := BorrowEncoder(nil)
420 enc.isPooled = 1
421 defer func() {
422 err := recover()
423 assert.NotNil(t, err, "err shouldnt be nil")
424 assert.IsType(t, InvalidUsagePooledEncoderError(""), err, "err should be of type InvalidUsagePooledEncoderError")
425 assert.Equal(t, "Invalid usage of pooled encoder", err.(InvalidUsagePooledEncoderError).Error(), "err should be of type InvalidUsagePooledDecoderError")
426 }()
427 _ = enc.EncodeObject(v)
428 assert.True(t, false, "should not be called as it should have panicked")
429 })
430}
431
432func TestEncoderObjectKeyNullEmpty(t *testing.T) {
433 var testCases = []struct {

Callers

nothing calls this directly

Calls 7

EncodeObjectMethod · 0.95
NewEncoderFunction · 0.85
TestWriterErrorTypeAlias · 0.85
BorrowEncoderFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…