Sha256: 775c098a60314232fc0a8f6e4679a58acb912dcbaf406fedf33593569deefc5a

Contents?: true

Size: 1.77 KB

Versions: 28

Compression:

Stored size: 1.77 KB

Contents

require 'webmock/rspec'

# This spec verifies the monkey-patch that we have to apply until the avro
# gem releases a fix for bug AVRO-1848:
# https://issues.apache.org/jira/browse/AVRO-1848

describe Avro::Schema do
  it "correctly handles falsey field defaults" do
    schema = Avro::Schema.parse <<-SCHEMA
      {"type": "record", "name": "Record", "namespace": "my.name.space",
        "fields": [
          {"name": "is_usable", "type": "boolean", "default": false}
        ]
      }
    SCHEMA
    
    expect(schema.to_avro).to eq({
      'type' => 'record', 'name' => 'Record', 'namespace' => 'my.name.space',
      'fields' => [
        {'name' => 'is_usable', 'type' => 'boolean', 'default' => false}
      ]
    })
  end
end


describe Avro::IO::DatumReader do
  let(:writer_schema) do
    Avro::Schema.parse <<-AVSC
      {
        "name": "no_default",
        "type": "record",
        "fields": [
          { "type": "string", "name": "one" }
        ]
      }
    AVSC
  end
  let(:reader_schema) do
    Avro::Schema.parse <<-AVSC
      {
        "name": "no_default",
        "type": "record",
        "fields": [
          { "type": "string", "name": "one" },
          { "type": "string", "name": "two" }
        ]
      }
    AVSC
  end

  it "raises an error for missing fields without a default" do
    stream = StringIO.new
    writer = Avro::IO::DatumWriter.new(writer_schema)
    encoder = Avro::IO::BinaryEncoder.new(stream)
    writer.write({ 'one' => 'first' }, encoder)
    encoded = stream.string

    stream = StringIO.new(encoded)
    decoder = Avro::IO::BinaryDecoder.new(stream)
    reader = Avro::IO::DatumReader.new(writer_schema, reader_schema)
    expect do
      reader.read(decoder)
    end.to raise_error(Avro::AvroError, 'Missing data for "string" with no default')
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
avro_turf-1.17.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.16.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.15.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.14.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.13.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.12.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.11.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.10.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.9.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.8.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.7.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.6.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.5.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.4.1 spec/schema_to_avro_patch_spec.rb
avro_turf-1.4.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.3.1 spec/schema_to_avro_patch_spec.rb
avro_turf-1.3.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.2.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.1.0 spec/schema_to_avro_patch_spec.rb
avro_turf-1.0.0 spec/schema_to_avro_patch_spec.rb