debian-mirror-gitlab/spec/services/ci/generate_kubeconfig_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.8 KiB
Ruby
Raw Normal View History

2021-12-11 22:18:48 +05:30
# 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) }
2022-07-16 23:28:13 +05:30
let(:pipeline) { build.pipeline }
2021-12-11 22:18:48 +05:30
let(:agent1) { create(:cluster_agent, project: project) }
let(:agent2) { create(:cluster_agent) }
2022-11-25 23:54:43 +05:30
let(:authorization1) { create(:agent_project_authorization, agent: agent1) }
let(:authorization2) { create(:agent_project_authorization, agent: agent2) }
2021-12-11 22:18:48 +05:30
let(:template) { instance_double(Gitlab::Kubernetes::Kubeconfig::Template) }
2022-07-16 23:28:13 +05:30
subject { described_class.new(pipeline, token: build.token).execute }
2021-12-11 22:18:48 +05:30
before do
expect(Gitlab::Kubernetes::Kubeconfig::Template).to receive(:new).and_return(template)
2022-11-25 23:54:43 +05:30
expect(pipeline).to receive(:cluster_agent_authorizations).and_return([authorization1, authorization2])
2021-12-11 22:18:48 +05:30
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}",
2022-11-25 23:54:43 +05:30
namespace: 'production',
2021-12-11 22:18:48 +05:30
cluster: 'gitlab',
user: "agent:#{agent1.id}"
)
expect(template).to receive(:add_context).with(
name: "#{agent2.project.full_path}:#{agent2.name}",
2022-11-25 23:54:43 +05:30
namespace: 'production',
2021-12-11 22:18:48 +05:30
cluster: 'gitlab',
user: "agent:#{agent2.id}"
)
expect(subject).to eq(template)
end
end
end