@@ -669,7 +669,7 @@ func TestEncoder_DurationInvalidSchema(t *testing.T) {
669669func TestEncoder_BytesRat_Positive (t * testing.T ) {
670670 defer ConfigTeardown ()
671671
672- schema := `{"type":"bytes","logicalType":"decimal","precision":4 ,"scale":2}`
672+ schema := `{"type":"bytes","logicalType":"decimal","precision":5 ,"scale":2}`
673673 buf := bytes .NewBuffer ([]byte {})
674674 enc , err := avro .NewEncoder (schema , buf )
675675 require .NoError (t , err )
@@ -683,7 +683,7 @@ func TestEncoder_BytesRat_Positive(t *testing.T) {
683683func TestEncoder_BytesRat_Negative (t * testing.T ) {
684684 defer ConfigTeardown ()
685685
686- schema := `{"type":"bytes","logicalType":"decimal","precision":4 ,"scale":2}`
686+ schema := `{"type":"bytes","logicalType":"decimal","precision":5 ,"scale":2}`
687687 buf := bytes .NewBuffer ([]byte {})
688688 enc , err := avro .NewEncoder (schema , buf )
689689 require .NoError (t , err )
@@ -697,7 +697,7 @@ func TestEncoder_BytesRat_Negative(t *testing.T) {
697697func TestEncoder_BytesRat_Zero (t * testing.T ) {
698698 defer ConfigTeardown ()
699699
700- schema := `{"type":"bytes","logicalType":"decimal","precision":4 ,"scale":2}`
700+ schema := `{"type":"bytes","logicalType":"decimal","precision":5 ,"scale":2}`
701701 buf := bytes .NewBuffer ([]byte {})
702702 enc , err := avro .NewEncoder (schema , buf )
703703 require .NoError (t , err )
@@ -708,10 +708,24 @@ func TestEncoder_BytesRat_Zero(t *testing.T) {
708708 assert .Equal (t , []byte {0x02 , 0x00 }, buf .Bytes ())
709709}
710710
711+ func TestEncoder_BytesRat_TooManyDigits (t * testing.T ) {
712+ defer ConfigTeardown ()
713+
714+ schema := `{"type":"bytes","logicalType":"decimal","precision":3,"scale":2}`
715+ buf := bytes .NewBuffer ([]byte {})
716+ enc , err := avro .NewEncoder (schema , buf )
717+ require .NoError (t , err )
718+
719+ err = enc .Encode (big .NewRat (1734 , 5 ))
720+
721+ assert .ErrorContains (t , err , "avro: cannot encode 346.80 as Avro bytes.decimal with precision=3, has 5 significant digits" )
722+ assert .Empty (t , buf .Bytes ())
723+ }
724+
711725func TestEncoder_BytesRatNonPtr_Positive (t * testing.T ) {
712726 defer ConfigTeardown ()
713727
714- schema := `{"type":"bytes","logicalType":"decimal","precision":4 ,"scale":2}`
728+ schema := `{"type":"bytes","logicalType":"decimal","precision":5 ,"scale":2}`
715729 buf := bytes .NewBuffer ([]byte {})
716730 enc , err := avro .NewEncoder (schema , buf )
717731 require .NoError (t , err )
@@ -725,7 +739,7 @@ func TestEncoder_BytesRatNonPtr_Positive(t *testing.T) {
725739func TestEncoder_BytesRatNonPtr_Negative (t * testing.T ) {
726740 defer ConfigTeardown ()
727741
728- schema := `{"type":"bytes","logicalType":"decimal","precision":4 ,"scale":2}`
742+ schema := `{"type":"bytes","logicalType":"decimal","precision":5 ,"scale":2}`
729743 buf := bytes .NewBuffer ([]byte {})
730744 enc , err := avro .NewEncoder (schema , buf )
731745 require .NoError (t , err )
@@ -739,7 +753,7 @@ func TestEncoder_BytesRatNonPtr_Negative(t *testing.T) {
739753func TestEncoder_BytesRatNonPtr_Zero (t * testing.T ) {
740754 defer ConfigTeardown ()
741755
742- schema := `{"type":"bytes","logicalType":"decimal","precision":4 ,"scale":2}`
756+ schema := `{"type":"bytes","logicalType":"decimal","precision":5 ,"scale":2}`
743757 buf := bytes .NewBuffer ([]byte {})
744758 enc , err := avro .NewEncoder (schema , buf )
745759 require .NoError (t , err )
@@ -750,6 +764,20 @@ func TestEncoder_BytesRatNonPtr_Zero(t *testing.T) {
750764 assert .Equal (t , []byte {0x02 , 0x00 }, buf .Bytes ())
751765}
752766
767+ func TestEncoder_BytesRatNonPtr_TooManyDigits (t * testing.T ) {
768+ defer ConfigTeardown ()
769+
770+ schema := `{"type":"bytes","logicalType":"decimal","precision":3,"scale":2}`
771+ buf := bytes .NewBuffer ([]byte {})
772+ enc , err := avro .NewEncoder (schema , buf )
773+ require .NoError (t , err )
774+
775+ err = enc .Encode (* big .NewRat (1734 , 5 ))
776+
777+ assert .ErrorContains (t , err , "avro: cannot encode 346.80 as Avro bytes.decimal with precision=3, has 5 significant digits" )
778+ assert .Empty (t , buf .Bytes ())
779+ }
780+
753781func TestEncoder_BytesRatInvalidSchema (t * testing.T ) {
754782 defer ConfigTeardown ()
755783
0 commit comments