Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Aug 7, 2020
1 parent b791526 commit c31a526
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions spec/messaging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,86 @@
it { expect { encode }.to raise_error(Avro::SchemaValidator::ValidationError, /extra field 'fulll_name'/) }
end
end

context 'fetching and registering schema' do
let(:schema_store) { AvroTurf::SchemaStore.new(path: "spec/schemas") }

let(:registry) { AvroTurf::ConfluentSchemaRegistry.new(registry_url, logger: logger) }

let(:avro) do
AvroTurf::Messaging.new(
registry: registry,
schema_store: schema_store,
logger: logger
)
end

let(:schema_id) { 234 }

context 'using fetch_schema' do
subject { avro.fetch_schema(subject: subj, version: version) }

let(:subj) { 'subject' }

let(:version) { 'version' }

let(:response) { {'id' => schema_id, 'schema' => schema_json} }

before do
allow(registry).to receive(:subject_version).with(subj, version).and_return(response)
end

it 'gets schema from registry' do
expect(subject).to eq([schema, schema_id])
end
end

context 'using fetch_schema_by_id' do
subject { avro.fetch_schema_by_id(schema_id) }

before do
allow(registry).to receive(:fetch).with(schema_id).and_return(schema_json)
end

it 'gets schema from registry' do
expect(subject).to eq([schema, schema_id])
end
end

context 'using register_schema' do
let(:schema_name) { 'schema_name' }

let(:namespace) { 'namespace' }

before do
allow(schema_store).to receive(:find).with(schema_name, namespace).and_return(schema)
end

context 'when subject is not set' do
subject { avro.register_schema(schema_name: schema_name, namespace: namespace) }

before do
allow(registry).to receive(:register).with(schema.fullname, schema).and_return(schema_id)
end

it 'registers schema in registry' do
expect(subject).to eq([schema, schema_id])
end
end

context 'when subject is set' do
subject { avro.register_schema(schema_name: schema_name, namespace: namespace, subject: subj) }

let(:subj) { 'subject' }

before do
allow(registry).to receive(:register).with(subj, schema).and_return(schema_id)
end

it 'registers schema in registry' do
expect(subject).to eq([schema, schema_id])
end
end
end
end
end

0 comments on commit c31a526

Please sign in to comment.