(t *testing.T)
| 394 | } |
| 395 | |
| 396 | func 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 | |
| 432 | func TestEncoderObjectKeyNullEmpty(t *testing.T) { |
| 433 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…