Sha256: a9d6064a40020702aa630807a217d2eff4109517dda71107cc79406f4dad8eff

Contents?: true

Size: 1.27 KB

Versions: 9

Compression:

Stored size: 1.27 KB

Contents

RSpec.describe Gorynich::Fetchers::ConsulSecure do
  let(:storage) { Faker::Lorem.word }
  let(:file_path) { "#{RSPEC_ROOT}/fixtures/fetchers/file_config.yml" }
  let(:file_like_object) { double("file like object") }

  context '#fetch' do
    let(:consul_host) { Faker::Internet.url }
    let(:consul_opts) { { http_addr: consul_host } }

    def consul_request(response, code = 200)
      stub_request(:get, "#{consul_host}/v1/kv/#{storage}?recurse=true")
        .to_return(
          status: code,
          body: response
        )
    end

    subject { described_class.new(storage: storage, file_path: file_path, **consul_opts) }

    describe 'when consul return data' do
      let(:response) { [{ 'Key' => "#{storage}/test_key", 'Value' => Base64.encode64('test') }].to_json }

      before(:each) do
        consul_request(response)
      end

      it do
        allow(File).to receive(:open).with(file_path, 'w').and_return(file_like_object)
        expect(subject.fetch).to eq({ 'test_key' => 'test' })
      end
    end

    describe 'when http error' do
      before(:each) do
        consul_request([], 500)
      end

      it do
        result = subject.fetch
        expect(result.class).to eq(Hash)
        expect(result).to include('development', 'test')
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gorynich-1.3.4.273062 spec/lib/gorynich/fetchers/consul_secure_spec.rb
gorynich-1.3.3.231946 spec/lib/gorynich/fetchers/consul_secure_spec.rb
gorynich-1.3.2.231715 spec/lib/gorynich/fetchers/consul_secure_spec.rb
gorynich-1.3.1.213701 spec/lib/gorynich/fetchers/consul_secure_spec.rb
gorynich-1.3.0.213297 spec/lib/gorynich/fetchers/consul_secure_spec.rb
gorynich-1.2.3.198656 spec/lib/gorynich/fetchers/consul_secure_spec.rb
gorynich-1.2.2.198643 spec/lib/gorynich/fetchers/consul_secure_spec.rb
gorynich-1.2.1.184916 spec/lib/gorynich/fetchers/consul_secure_spec.rb
gorynich-1.2.0.180668 spec/lib/gorynich/fetchers/consul_secure_spec.rb