Sha256: fb6567f5075da9d63bbac324e0f41ae3d8a29d6b227f491dc048bbccf90951ae

Contents?: true

Size: 1.73 KB

Versions: 6

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'
require 'pry'

describe LearnOpen::GitSSHConnector do
  let(:git_server) { 'github.example.com' }
  let(:ssh_adapter_instance) { instance_double(LearnOpen::Adapters::SshAdapter) }
  let(:ssh_adapter) { class_double(LearnOpen::Adapters::SshAdapter) }
  let(:ssh_connector) { LearnOpen::GitSSHConnector.new(git_server: git_server, environment: environment) }
  let(:environment) { instance_double(LearnOpen::Environments::IDEEnvironment) }

  before do
    allow(LearnOpen).to receive(:ssh_adapter).and_return(ssh_adapter)
    allow(ssh_adapter).to receive(:new).with(user: 'git', hostname: git_server).and_return(ssh_adapter_instance)
  end

  context 'for an authenticated SSH connection' do
    before do
      allow(ssh_adapter_instance).to receive(:authenticated?).and_return(true)
      allow(environment).to receive(:managed?).and_return(true)
    end

    it 'does not attempt to upload keys' do
      expect(ssh_connector).to_not receive(:upload_ssh_keys!)
      ssh_connector.call
    end
  end

  context 'for an unauthenticated SSH connection' do
    before do
      allow(ssh_adapter_instance).to receive(:authenticated?).and_return(false)
    end

    context 'on a managed server' do
      before do
        allow(environment).to receive(:managed?).and_return(true)
      end

      it 'attempts to upload a key' do
        expect(ssh_connector).to receive(:upload_ssh_keys!).exactly(:once)
        ssh_connector.call
      end
    end

    context 'on an unmanaged server' do
      before do
        allow(environment).to receive(:managed?).and_return(false)
      end

      it 'does not attempt to upload a key' do
        expect(ssh_connector).to_not receive(:upload_ssh_keys!)
        ssh_connector.call
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
learn-open-1.2.28 spec/learn_open/services/git_ssh_connector_spec.rb
learn-open-1.2.27 spec/learn_open/services/git_ssh_connector_spec.rb
learn-open-1.2.26 spec/learn_open/services/git_ssh_connector_spec.rb
learn-open-1.2.24 spec/learn_open/services/git_ssh_connector_spec.rb
learn-open-1.2.23 spec/learn_open/services/git_ssh_connector_spec.rb
learn-open-1.2.22 spec/learn_open/services/git_ssh_connector_spec.rb