Sha256: d6769dc1c30e7f73b0bf33c93fde1dcac090b01e0f99a5fdeabd84ffb50eaa26

Contents?: true

Size: 1.99 KB

Versions: 14

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

describe Dockly::BuildCache::Base do
  subject { described_class.new(:name => :test_build_cache) }

  before do
    subject.s3_bucket 'lol'
    subject.s3_object_prefix 'swag'
    subject.hash_command 'md5sum /etc/vim/vimrc'
    subject.build_command 'touch lol'
    subject.output_dir '/'
  end

  describe '#up_to_date?' do
    context 'when the object exists in s3' do
      before do
        allow(subject.connection)
          .to receive(:head_object)
      end

      its(:up_to_date?) { should be_true }
    end

    context 'when the object does not exist in s3' do
      before do
        allow(subject.connection)
          .to receive(:head_object)
          .and_raise(Aws::S3::Errors::NoSuchKey.new('Some Error', 500))
      end

      its(:up_to_date?) { should be_false }
    end
  end

  describe '#pull_from_s3' do
    let(:file) { subject.pull_from_s3('hey') }
    let(:object) { double(:object) }

    before do
      allow(subject.connection)
        .to receive(:get_object)
        .and_return(object)
      allow(object)
        .to receive(:body)
        .and_return(StringIO.new('hey dad').tap(&:rewind))
    end

    after do
      path = file.path
      file.close
      File.delete(path)
    end

    it 'returns a File with the data pulled' do
      file.read.should == 'hey dad'
    end
  end

  describe '#s3_object' do
    before do
      allow(subject).to receive(:s3_object_prefix).and_return('lol')
      allow(subject).to receive(:hash_output).and_return('lel')
    end

    context "without an arch_output" do
      it 'returns the s3_prefix merged with the hash_output' do
        subject.s3_object(subject.hash_output).should == 'lollel'
      end
    end

    context "with an arch_output" do
      before do
        subject.parameter_command "linux"
        subject.stub(:parameter_output) { "linux" }
      end

      it 'returns the s3_prefix merged with the hash_output' do
        subject.s3_object(subject.hash_output).should == 'lollinux_lel'
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
dockly-4.1.0 spec/dockly/build_cache/base_spec.rb
dockly-4.0.0 spec/dockly/build_cache/base_spec.rb
dockly-3.4.1 spec/dockly/build_cache/base_spec.rb
dockly-3.4.0 spec/dockly/build_cache/base_spec.rb
dockly-3.3.0 spec/dockly/build_cache/base_spec.rb
dockly-3.2.0.pre.1 spec/dockly/build_cache/base_spec.rb
dockly-3.1.1 spec/dockly/build_cache/base_spec.rb
dockly-3.1.0 spec/dockly/build_cache/base_spec.rb
dockly-3.0.5 spec/dockly/build_cache/base_spec.rb
dockly-3.0.4 spec/dockly/build_cache/base_spec.rb
dockly-3.0.3 spec/dockly/build_cache/base_spec.rb
dockly-3.0.2 spec/dockly/build_cache/base_spec.rb
dockly-3.0.1 spec/dockly/build_cache/base_spec.rb
dockly-3.0.0 spec/dockly/build_cache/base_spec.rb