Sha256: 6c19679b7986b3c508a55de7676c3fde8546f6dc890579824352851abc337055

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

require 'ostruct'
require 'spec_helper'

class Database < OpenStruct
end

describe Aptible::CLI::Agent do
  before { subject.stub(:ask) }
  before { subject.stub(:save_token) }
  before { subject.stub(:fetch_token) { double 'token' } }
  before { subject.stub(:random_local_port) { 4242 } }
  before { subject.stub(:establish_connection) }

  let(:database) do
    Database.new(
      type: 'postgresql',
      handle: 'foobar',
      passphrase: 'password',
      connection_url: 'postgresql://aptible:password@10.252.1.125:49158/db'
    )
  end

  describe '#db:tunnel' do
    it 'should fail if database is non-existent' do
      allow(Aptible::Api::Database).to receive(:all) { [] }
      expect do
        subject.send('db:tunnel', 'foobar')
      end.to raise_error('Could not find database foobar')
    end

    it 'should print a message about how to connect' do
      allow(Aptible::Api::Database).to receive(:all) { [database] }
      local_url = 'postgresql://aptible:password@127.0.0.1:4242/db'
      expect(subject).to receive(:say).with('Creating tunnel...', :green)
      expect(subject).to receive(:say).with("Connect at #{local_url}", :green)

      # db:tunnel should also explain each component of the URL:
      expect(subject).to receive(:say).exactly(6).times
      subject.send('db:tunnel', 'foobar')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aptible-cli-0.5.13 spec/aptible/cli/subcommands/db_spec.rb
aptible-cli-0.5.12 spec/aptible/cli/subcommands/db_spec.rb