test/test_schema.rb in avro-salsify-fork-1.9.0.2 vs test/test_schema.rb in avro-salsify-fork-1.9.0.3.pre1

- old
+ new

@@ -156,6 +156,57 @@ SCHEMA end assert_equal '"MissingType" is not a schema we know about.', error.message end + + def test_to_avro_handles_falsey_defaults + schema = Avro::Schema.parse <<-SCHEMA + {"type": "record", "name": "Record", "namespace": "my.name.space", + "fields": [ + {"name": "is_usable", "type": "boolean", "default": false} + ] + } + SCHEMA + + assert_equal schema.to_avro, { + 'type' => 'record', 'name' => 'Record', 'namespace' => 'my.name.space', + 'fields' => [ + {'name' => 'is_usable', 'type' => 'boolean', 'default' => false} + ] + } + end + + def test_empty_record + schema = Avro::Schema.parse('{"type":"record", "name":"Empty"}') + assert_empty(schema.fields) + end + + def test_empty_union + schema = Avro::Schema.parse('[]') + assert_equal(schema.to_s, '[]') + end + + def test_read + schema = Avro::Schema.parse('"string"') + writer_schema = Avro::Schema.parse('"int"') + assert_false(schema.read?(writer_schema)) + assert_true(schema.read?(schema)) + end + + def test_be_read + schema = Avro::Schema.parse('"string"') + writer_schema = Avro::Schema.parse('"int"') + assert_false(schema.be_read?(writer_schema)) + assert_true(schema.be_read?(schema)) + end + + def test_mutual_read + schema = Avro::Schema.parse('"string"') + writer_schema = Avro::Schema.parse('"int"') + default1 = Avro::Schema.parse('{"type":"record", "name":"Default", "fields":[{"name":"i", "type":"int", "default": 1}]}') + default2 = Avro::Schema.parse('{"type":"record", "name":"Default", "fields":[{"name:":"s", "type":"string", "default": ""}]}') + assert_false(schema.mutual_read?(writer_schema)) + assert_true(schema.mutual_read?(schema)) + assert_true(default1.mutual_read?(default2)) + end end