metadata_spec.rb 2.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
require 'spec_helper'

describe Gitlab::Ci::Build::Artifacts::Metadata do
  def metadata(path = '')
    described_class.new(metadata_file_path, path)
  end

  let(:metadata_file_path) do
    Rails.root + 'spec/fixtures/ci_build_artifacts_metadata.gz'
  end

  context 'metadata file exists' do
13 14
    describe '#find_entries! empty string' do
      subject { metadata('').find_entries! }
15 16

      it 'matches correct paths' do
17 18 19 20
        expect(subject.keys).to contain_exactly 'ci_artifacts.txt',
                                                'other_artifacts_0.1.2/',
                                                'rails_sample.jpg',
                                                'tests_encoding/'
21 22 23
      end

      it 'matches metadata for every path' do
24
        expect(subject.keys.count).to eq 4
25 26 27
      end

      it 'return Hashes for each metadata' do
28
        expect(subject.values).to all(be_kind_of(Hash))
29 30 31
      end
    end

32 33
    describe '#find_entries! other_artifacts_0.1.2/' do
      subject { metadata('other_artifacts_0.1.2/').find_entries! }
34 35

      it 'matches correct paths' do
36
        expect(subject.keys).
37 38
          to contain_exactly 'other_artifacts_0.1.2/',
                             'other_artifacts_0.1.2/doc_sample.txt',
39 40 41 42
                             'other_artifacts_0.1.2/another-subdirectory/'
      end
    end

43 44
    describe '#find_entries! other_artifacts_0.1.2/another-subdirectory/' do
      subject { metadata('other_artifacts_0.1.2/another-subdirectory/').find_entries! }
45 46

      it 'matches correct paths' do
47
        expect(subject.keys).
48 49
          to contain_exactly 'other_artifacts_0.1.2/another-subdirectory/',
                             'other_artifacts_0.1.2/another-subdirectory/empty_directory/',
50 51 52 53
                             'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif'
      end
    end

54 55 56
    describe '#to_entry' do
      subject { metadata('').to_entry }
      it { is_expected.to be_an_instance_of(Gitlab::Ci::Build::Artifacts::Metadata::Entry) }
57
    end
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

    describe '#full_version' do
      subject { metadata('').full_version }
      it { is_expected.to eq 'GitLab Build Artifacts Metadata 0.0.1' }
    end

    describe '#version' do
      subject { metadata('').version }
      it { is_expected.to eq '0.0.1' }
    end

    describe '#errors' do
      subject { metadata('').errors }
      it { is_expected.to eq({}) }
    end
73 74 75 76 77
  end

  context 'metadata file does not exist' do
    let(:metadata_file_path) { '' }

78
    describe '#find_entries!' do
79
      it 'raises error' do
80
        expect { metadata.find_entries! }.to raise_error(Errno::ENOENT)
81 82 83 84
      end
    end
  end
end