2016-11-21 10:02:08 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Ci::Build::Credentials::Registry do
|
|
|
|
let(:build) { create(:ci_build, name: 'spinach', stage: 'test', stage_idx: 0) }
|
|
|
|
let(:registry_url) { 'registry.example.com:5005' }
|
|
|
|
|
2017-05-01 11:13:33 -04:00
|
|
|
subject { described_class.new(build) }
|
2016-11-21 10:02:08 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(host_port: registry_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains valid DockerRegistry credentials' do
|
2017-05-01 11:13:33 -04:00
|
|
|
expect(subject).to be_kind_of(described_class)
|
2016-11-21 10:02:08 -05:00
|
|
|
|
|
|
|
expect(subject.username).to eq 'gitlab-ci-token'
|
|
|
|
expect(subject.password).to eq build.token
|
|
|
|
expect(subject.url).to eq registry_url
|
|
|
|
expect(subject.type).to eq 'registry'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.valid?' do
|
2017-05-01 11:13:33 -04:00
|
|
|
subject { described_class.new(build).valid? }
|
2016-11-21 10:02:08 -05:00
|
|
|
|
|
|
|
context 'when registry is enabled' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when registry is disabled' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(enabled: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|