2021-10-26 20:13:04 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Cluster agent registration', :js do
|
|
|
|
let_it_be(:project) { create(:project, :custom_repo, files: { '.gitlab/agents/example-agent-1/config.yaml' => '' }) }
|
|
|
|
let_it_be(:current_user) { create(:user, maintainer_projects: [project]) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Gitlab::Kas).to receive(:enabled?).and_return(true)
|
|
|
|
allow(Gitlab::Kas).to receive(:internal_url).and_return('kas.example.internal')
|
|
|
|
|
|
|
|
allow_next_instance_of(Gitlab::Kas::Client) do |client|
|
|
|
|
allow(client).to receive(:list_agent_config_files).and_return([
|
|
|
|
double(agent_name: 'example-agent-1', path: '.gitlab/agents/example-agent-1/config.yaml'),
|
|
|
|
double(agent_name: 'example-agent-2', path: '.gitlab/agents/example-agent-2/config.yaml')
|
|
|
|
])
|
2022-02-04 04:14:46 -05:00
|
|
|
allow(client).to receive(:get_connected_agents).and_return([])
|
2021-10-26 20:13:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
allow(Devise).to receive(:friendly_token).and_return('example-agent-token')
|
|
|
|
|
|
|
|
sign_in(current_user)
|
|
|
|
visit project_clusters_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows the user to select an agent to install, and displays the resulting agent token' do
|
2021-11-15 10:10:57 -05:00
|
|
|
click_button('Actions')
|
2021-12-02 16:10:16 -05:00
|
|
|
expect(page).to have_content('Register')
|
2021-10-26 20:13:04 -04:00
|
|
|
|
2021-12-02 16:10:16 -05:00
|
|
|
click_button('Select an agent')
|
2021-10-26 20:13:04 -04:00
|
|
|
click_button('example-agent-2')
|
2021-12-02 16:10:16 -05:00
|
|
|
click_button('Register')
|
2021-10-26 20:13:04 -04:00
|
|
|
|
2021-12-02 16:10:16 -05:00
|
|
|
expect(page).to have_content('You cannot see this token again after you close this window.')
|
2021-10-26 20:13:04 -04:00
|
|
|
expect(page).to have_content('example-agent-token')
|
|
|
|
expect(page).to have_content('docker run --pull=always --rm')
|
|
|
|
|
2021-11-15 10:10:57 -05:00
|
|
|
within find('.modal-footer') do
|
|
|
|
click_button('Close')
|
|
|
|
end
|
|
|
|
|
2021-10-26 20:13:04 -04:00
|
|
|
expect(page).to have_link('example-agent-2')
|
|
|
|
end
|
|
|
|
end
|