summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/build/credentials/factory_spec.rb
blob: 10b4b7a882684e1a866ac6cbab4890bbb6bd8e57 (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
require 'spec_helper'

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

  subject { Gitlab::Ci::Build::Credentials::Factory.new(build).create! }

  class TestProvider
    def initialize(build); end
  end

  before do
    allow_any_instance_of(Gitlab::Ci::Build::Credentials::Factory).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