2017-10-04 09:40:12 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Ci::FetchKubernetesTokenService do
|
|
|
|
describe '#execute' do
|
2017-10-05 07:26:07 -04:00
|
|
|
subject { described_class.new(api_url, ca_pem, username, password).execute }
|
|
|
|
|
|
|
|
let(:api_url) { 'http://111.111.111.111' }
|
|
|
|
let(:ca_pem) { '' }
|
|
|
|
let(:username) { 'admin' }
|
|
|
|
let(:password) { 'xxx' }
|
|
|
|
|
|
|
|
context 'when params correct' do
|
|
|
|
let(:token) { 'xxx.token.xxx' }
|
|
|
|
|
|
|
|
let(:secrets_json) do
|
|
|
|
[
|
|
|
|
{
|
|
|
|
'metadata': {
|
|
|
|
name: metadata_name
|
|
|
|
},
|
|
|
|
'data': {
|
|
|
|
'token': Base64.encode64(token)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Kubeclient::Client)
|
|
|
|
.to receive(:get_secrets).and_return(secrets_json)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when default-token exists' do
|
|
|
|
let(:metadata_name) { 'default-token-123' }
|
|
|
|
|
|
|
|
it { is_expected.to eq(token) }
|
2017-10-04 09:40:12 -04:00
|
|
|
end
|
|
|
|
|
2017-10-05 07:26:07 -04:00
|
|
|
context 'when default-token does not exist' do
|
|
|
|
let(:metadata_name) { 'another-token-123' }
|
2017-10-04 09:40:12 -04:00
|
|
|
|
2017-10-05 07:26:07 -04:00
|
|
|
it { is_expected.to be_nil }
|
2017-10-04 09:40:12 -04:00
|
|
|
end
|
|
|
|
end
|
2017-10-05 07:26:07 -04:00
|
|
|
|
|
|
|
context 'when api_url is nil' do
|
|
|
|
let(:api_url) { nil }
|
|
|
|
|
|
|
|
it { expect { subject }.to raise_error("Incomplete settings") }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when username is nil' do
|
|
|
|
let(:username) { nil }
|
|
|
|
|
|
|
|
it { expect { subject }.to raise_error("Incomplete settings") }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when password is nil' do
|
|
|
|
let(:password) { nil }
|
|
|
|
|
|
|
|
it { expect { subject }.to raise_error("Incomplete settings") }
|
|
|
|
end
|
2017-10-04 09:40:12 -04:00
|
|
|
end
|
|
|
|
end
|