Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 16:16:36 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 16:16:36 +0300
commit311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch)
tree07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/services/ci/generate_kubeconfig_service_spec.rb
parent27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff)
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/services/ci/generate_kubeconfig_service_spec.rb')
-rw-r--r--spec/services/ci/generate_kubeconfig_service_spec.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/services/ci/generate_kubeconfig_service_spec.rb b/spec/services/ci/generate_kubeconfig_service_spec.rb
new file mode 100644
index 00000000000..b0673d16158
--- /dev/null
+++ b/spec/services/ci/generate_kubeconfig_service_spec.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::GenerateKubeconfigService do
+ describe '#execute' do
+ let(:project) { create(:project) }
+ let(:build) { create(:ci_build, project: project) }
+ let(:agent1) { create(:cluster_agent, project: project) }
+ let(:agent2) { create(:cluster_agent) }
+
+ let(:template) { instance_double(Gitlab::Kubernetes::Kubeconfig::Template) }
+
+ subject { described_class.new(build).execute }
+
+ before do
+ expect(Gitlab::Kubernetes::Kubeconfig::Template).to receive(:new).and_return(template)
+ expect(build.pipeline).to receive(:authorized_cluster_agents).and_return([agent1, agent2])
+ end
+
+ it 'adds a cluster, and a user and context for each available agent' do
+ expect(template).to receive(:add_cluster).with(
+ name: 'gitlab',
+ url: Gitlab::Kas.tunnel_url
+ ).once
+
+ expect(template).to receive(:add_user).with(
+ name: "agent:#{agent1.id}",
+ token: "ci:#{agent1.id}:#{build.token}"
+ )
+ expect(template).to receive(:add_user).with(
+ name: "agent:#{agent2.id}",
+ token: "ci:#{agent2.id}:#{build.token}"
+ )
+
+ expect(template).to receive(:add_context).with(
+ name: "#{project.full_path}:#{agent1.name}",
+ cluster: 'gitlab',
+ user: "agent:#{agent1.id}"
+ )
+ expect(template).to receive(:add_context).with(
+ name: "#{agent2.project.full_path}:#{agent2.name}",
+ cluster: 'gitlab',
+ user: "agent:#{agent2.id}"
+ )
+
+ expect(subject).to eq(template)
+ end
+ end
+end