Sha256: fe985cb6989feae0c5bb270c8f60d9e94800f4ae3e99cdde64fbb3bf829b4310

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'webmock/rspec'
require 'avro_turf/cached_schema_registry'
require_relative '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

1 entries across 1 versions & 1 rubygems

Version Path
avro_turf-0.6.2 spec/cached_schema_registry_spec.rb