diff --git a/app/services/ci/fetch_kubernetes_token_service.rb b/app/services/ci/fetch_kubernetes_token_service.rb index 013e4f12682..44da87cb00c 100644 --- a/app/services/ci/fetch_kubernetes_token_service.rb +++ b/app/services/ci/fetch_kubernetes_token_service.rb @@ -22,6 +22,8 @@ module Ci return Base64.decode64(token_base64) if token_base64 end end + + nil end private diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index ee152872acc..777e9c8e21d 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -60,6 +60,7 @@ describe Gitlab::UsageData do deploy_keys deployments environments + gcp_clusters in_review_folder groups issues diff --git a/spec/models/gcp/cluster_spec.rb b/spec/models/gcp/cluster_spec.rb index 4b227a19bc2..350fbc257d9 100644 --- a/spec/models/gcp/cluster_spec.rb +++ b/spec/models/gcp/cluster_spec.rb @@ -122,12 +122,12 @@ describe Gcp::Cluster do let(:cluster) { create(:gcp_cluster) } before do - cluster.creating! + cluster.make_creating! end context 'when created' do before do - cluster.created! + cluster.make_created! end it { is_expected.to be_truthy } diff --git a/spec/services/ci/fetch_kubernetes_token_service_spec.rb b/spec/services/ci/fetch_kubernetes_token_service_spec.rb index b66b5a7947d..1d05c9671a9 100644 --- a/spec/services/ci/fetch_kubernetes_token_service_spec.rb +++ b/spec/services/ci/fetch_kubernetes_token_service_spec.rb @@ -2,16 +2,63 @@ require 'spec_helper' describe Ci::FetchKubernetesTokenService do describe '#execute' do - context 'when correct params' do - it 'fetch the kubernetes token' do - + 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) } + end + + context 'when default-token does not exist' do + let(:metadata_name) { 'another-token-123' } + + it { is_expected.to be_nil } end end - context 'when invalid params' do - it 'returns nil' do + context 'when api_url is nil' do + let(:api_url) { nil } - end + 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 end end