Sha256: 3cedf70487f0ed5ad0f763e3194088965ad86ec78f0b4ae756dce66f9be48bc4

Contents?: true

Size: 1.91 KB

Versions: 8

Compression:

Stored size: 1.91 KB

Contents

require 'spec_helper'

describe Etcdv3::Connection do

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

    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, nil, 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', nil, 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

8 entries across 8 versions & 2 rubygems

Version Path
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/spec/etcdv3/connection_spec.rb
etcdv3-0.11.6 spec/etcdv3/connection_spec.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/spec/etcdv3/connection_spec.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/spec/etcdv3/connection_spec.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/spec/etcdv3/connection_spec.rb
etcdv3-0.11.5 spec/etcdv3/connection_spec.rb
etcdv3-0.11.4 spec/etcdv3/connection_spec.rb
etcdv3-0.11.3 spec/etcdv3/connection_spec.rb