Sha256: 38c643e33afd3c5c50c2218024924baa98955aba37e22b732fbff428776f1e1d

Contents?: true

Size: 1.9 KB

Versions: 7

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

describe Etcdv3::Connection do

  describe '#initialize - without metadata' do
    subject { Etcdv3::Connection.new('http://localhost:2379', 10) }

    it { is_expected.to have_attributes(endpoint: URI('http://localhost:2379')) }
    it { is_expected.to have_attributes(credentials: :this_channel_is_insecure) }
    it { is_expected.to have_attributes(hostname: 'localhost:2379') }

    [:kv, :maintenance, :lease, :watch, :auth].each do |handler|
      let(:handler_stub) { subject.handlers[handler].instance_variable_get(:@stub) }
      let(:handler_metadata) { subject.handlers[handler].instance_variable_get(:@metadata) }
      it 'sets hostname' do
        expect(handler_stub.instance_variable_get(:@host)).to eq('localhost:2379')
      end
      it 'sets token' do
        expect(handler_metadata[:token]).to be_nil
      end
    end
  end

  describe '#initialize - with metadata' do
    subject { Etcdv3::Connection.new('http://localhost:2379', 10, token: 'token123') }

    [:kv, :maintenance, :lease, :watch, :auth].each do |handler|
      let(:handler_stub) { subject.handlers[handler].instance_variable_get(:@stub) }
      let(:handler_metadata) { subject.handlers[handler].instance_variable_get(:@metadata) }
      it 'sets hostname' do
        expect(handler_stub.instance_variable_get(:@host)).to eq('localhost:2379')
      end
      it 'sets token' do
        expect(handler_metadata[:token]).to eq('token123')
      end
    end
  end

  describe '#refresh_metadata' do
    subject { Etcdv3::Connection.new('http://localhost:2379', token: 'token123') }
    before { subject.refresh_metadata(token: 'newtoken') }
    [:kv, :maintenance, :lease, :watch, :auth].each do |handler|
      let(:handler_metadata) { subject.handlers[handler].instance_variable_get(:@metadata) }
      it 'rebuilds handlers with new token' do
        expect(handler_metadata[:token]).to eq('newtoken')
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
etcdv3-0.10.2 spec/etcdv3/connection_spec.rb
etcdv3-0.10.1 spec/etcdv3/connection_spec.rb
etcdv3-0.9.0 spec/etcdv3/connection_spec.rb
etcdv3-0.8.3 spec/etcdv3/connection_spec.rb
etcdv3-0.8.2 spec/etcdv3/connection_spec.rb
etcdv3-0.8.1 spec/etcdv3/connection_spec.rb
etcdv3-0.8.0 spec/etcdv3/connection_spec.rb