test/test_schema_validator.rb in avro-1.10.2 vs test/test_schema_validator.rb in avro-1.11.0

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the @@ -167,17 +168,17 @@ end def test_validate_float schema = hash_to_schema(type: 'float', name: 'name') - assert_valid_schema(schema, [1.1, 1, Avro::Schema::LONG_MAX_VALUE], ['string'], true) + assert_valid_schema(schema, [1.1, 1, BigDecimal('1.1'), Avro::Schema::LONG_MAX_VALUE], ['string'], true) end def test_validate_double schema = hash_to_schema(type: 'double', name: 'name') - assert_valid_schema(schema, [1.1, 1, Avro::Schema::LONG_MAX_VALUE], ['string'], true) + assert_valid_schema(schema, [1.1, 1, BigDecimal('1.1'), Avro::Schema::LONG_MAX_VALUE], ['string'], true) end def test_validate_fixed schema = hash_to_schema(type: 'fixed', name: 'name', size: 3) @@ -554,7 +555,21 @@ exception = assert_raise(Avro::SchemaValidator::ValidationError) do validate!(schema, { 'name' => 'apple', 'color' => 'green' }, fail_on_extra_fields: true) end assert_equal(1, exception.result.errors.size) assert_equal("at . extra field 'color' - not in schema", exception.to_s) + end + + def test_validate_bytes_decimal + schema = hash_to_schema(type: 'bytes', logicalType: 'decimal', precision: 4, scale: 2) + assert_valid_schema(schema, [BigDecimal('1.23'), 4.2, 1], ['4.2', BigDecimal('233.2')], true) + + schema = hash_to_schema(type: 'bytes', logicalType: 'decimal', precision: 4, scale: 4) + assert_valid_schema(schema, [BigDecimal('0.2345'), 0.2, 0.1], ['4.2', BigDecimal('233.2')], true) + + schema = hash_to_schema(type: 'bytes', logicalType: 'decimal', precision: 4, scale: 0) + assert_valid_schema(schema, [BigDecimal('123'), 2], ['4.2', BigDecimal('233.2')], true) + + schema = hash_to_schema(type: 'bytes', logicalType: 'decimal', precision: 4) + assert_valid_schema(schema, [BigDecimal('123'), 2], ['4.2', BigDecimal('233.2')], true) end end