Sha256: 179c2bfdda3c9d8ad9542addf8d61206e067db8ee9405d12e647b89fce275999

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

require 'webmock/rspec'
require 'avro_turf/cached_schema_registry'
require 'avro_turf/test/fake_schema_registry_server'

describe AvroTurf::CachedSchemaRegistry do
  let(:upstream) { instance_double(AvroTurf::SchemaRegistry) }
  let(:registry) { described_class.new(upstream) }
  let(:id) { rand(999) }
  let(:schema) do
    {
      type: "record",
      name: "person",
      fields: [{ name: "name", type: "string" }]
    }.to_json
  end

  describe "#fetch" do
    it "caches the result of fetch" do
      allow(upstream).to receive(:fetch).with(id).and_return(schema)
      registry.fetch(id)
      expect(registry.fetch(id)).to eq(schema)
      expect(upstream).to have_received(:fetch).exactly(1).times
    end
  end

  describe "#register" do
    let(:subject_name) { "a_subject" }

    it "caches the result of register" do
      allow(upstream).to receive(:register).with(subject_name, schema).and_return(id)
      registry.register(subject_name, schema)
      expect(registry.register(subject_name, schema)).to eq(id)
      expect(upstream).to have_received(:register).exactly(1).times
    end
  end

  it_behaves_like "a schema registry client" do
    let(:upstream) { AvroTurf::SchemaRegistry.new(registry_url, logger: logger) }
    let(:registry) { described_class.new(upstream) }
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
avro_turf_enchanced-0.7.4 spec/cached_schema_registry_spec.rb
avro_turf_enchanced-0.7.3 spec/cached_schema_registry_spec.rb
avro_turf-0.7.2 spec/cached_schema_registry_spec.rb
avro_turf-0.7.1 spec/cached_schema_registry_spec.rb
avro_turf-0.7.0 spec/cached_schema_registry_spec.rb