summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/build/credentials/factory_spec.rb
blob: 9148c0d579e960ab8f162f7b1af7ab75c9b734cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Ci::Build::Credentials::Factory do
  let(:build) { create(:ci_build, name: 'spinach', stage: 'test', stage_idx: 0) }

  subject { described_class.new(build).create! }

  class TestProvider
    def initialize(build); end
  end

  before do
    allow_any_instance_of(described_class).to receive(:providers).and_return([TestProvider])
  end

  context 'when provider is valid' do
    before do
      allow_any_instance_of(TestProvider).to receive(:valid?).and_return(true)
    end

    it 'generates an array of credentials objects' do
      is_expected.to be_kind_of(Array)
      is_expected.not_to be_empty
      expect(subject.first).to be_kind_of(TestProvider)
    end
  end

  context 'when provider is not valid' do
    before do
      allow_any_instance_of(TestProvider).to receive(:valid?).and_return(false)
    end

    it 'generates an array without specific credential object' do
      is_expected.to be_kind_of(Array)
      is_expected.to be_empty
    end
  end
end