2020-11-06 07:09:17 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Terraform', :js do
|
|
|
|
let_it_be(:project) { create(:project) }
|
2020-12-08 22:09:24 -05:00
|
|
|
let_it_be(:terraform_state) { create(:terraform_state, :locked, :with_version, project: project) }
|
2020-11-06 07:09:17 -05:00
|
|
|
|
2020-12-08 22:09:24 -05:00
|
|
|
context 'when user is a terraform administrator' do
|
|
|
|
let(:admin) { project.creator }
|
2020-11-06 07:09:17 -05:00
|
|
|
|
|
|
|
before do
|
2020-12-08 22:09:24 -05:00
|
|
|
gitlab_sign_in(admin)
|
2020-11-06 07:09:17 -05:00
|
|
|
end
|
|
|
|
|
2020-12-08 22:09:24 -05:00
|
|
|
context 'when user does not have any terraform states and visits the index page' do
|
|
|
|
let(:empty_project) { create(:project) }
|
2020-11-06 07:09:17 -05:00
|
|
|
|
|
|
|
before do
|
2020-12-08 22:09:24 -05:00
|
|
|
empty_project.add_maintainer(admin)
|
|
|
|
visit project_terraform_index_path(empty_project)
|
2020-11-06 07:09:17 -05:00
|
|
|
end
|
|
|
|
|
2020-12-08 22:09:24 -05:00
|
|
|
it 'sees an empty state' do
|
|
|
|
expect(page).to have_content('Get started with Terraform')
|
2020-11-06 07:09:17 -05:00
|
|
|
end
|
2020-12-08 22:09:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has a terraform state' do
|
|
|
|
context 'when user visits the index page' do
|
|
|
|
before do
|
|
|
|
visit project_terraform_index_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays a tab with states count' do
|
|
|
|
expect(page).to have_content("States #{project.terraform_states.size}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays a table with terraform states' do
|
|
|
|
expect(page).to have_selector(
|
2021-08-12 11:09:58 -04:00
|
|
|
"[data-testid='terraform-states-table-name']",
|
2020-12-08 22:09:24 -05:00
|
|
|
count: project.terraform_states.size
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays terraform actions dropdown' do
|
|
|
|
expect(page).to have_selector(
|
|
|
|
'[data-testid*="terraform-state-actions"]',
|
|
|
|
count: project.terraform_states.size
|
|
|
|
)
|
|
|
|
end
|
2020-11-06 07:09:17 -05:00
|
|
|
|
2020-12-08 22:09:24 -05:00
|
|
|
it 'displays terraform information' do
|
|
|
|
expect(page).to have_content(terraform_state.name)
|
|
|
|
end
|
|
|
|
end
|
2020-12-16 13:10:10 -05:00
|
|
|
|
|
|
|
context 'when clicking on the delete button' do
|
|
|
|
let(:additional_state) { create(:terraform_state, project: project) }
|
|
|
|
|
2021-06-30 11:08:27 -04:00
|
|
|
it 'removes the state', :aggregate_failures, quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/333640' do
|
2020-12-16 13:10:10 -05:00
|
|
|
visit project_terraform_index_path(project)
|
|
|
|
|
|
|
|
expect(page).to have_content(additional_state.name)
|
|
|
|
|
|
|
|
find("[data-testid='terraform-state-actions-#{additional_state.name}']").click
|
2021-08-12 11:09:58 -04:00
|
|
|
find("[data-testid='terraform-state-remove']").click
|
2020-12-16 13:10:10 -05:00
|
|
|
fill_in "terraform-state-remove-input-#{additional_state.name}", with: additional_state.name
|
|
|
|
click_button 'Remove'
|
|
|
|
|
2021-02-15 07:09:29 -05:00
|
|
|
expect(page).to have_content("#{additional_state.name} successfully removed")
|
2020-12-16 13:10:10 -05:00
|
|
|
expect { additional_state.reload }.to raise_error ActiveRecord::RecordNotFound
|
|
|
|
end
|
|
|
|
end
|
2021-08-12 11:09:58 -04:00
|
|
|
|
|
|
|
context 'when clicking on copy Terraform init command' do
|
|
|
|
it 'shows the modal with the init command' do
|
|
|
|
visit project_terraform_index_path(project)
|
|
|
|
|
|
|
|
expect(page).to have_content(terraform_state.name)
|
|
|
|
|
|
|
|
page.within("[data-testid='terraform-state-actions-#{terraform_state.name}']") do
|
|
|
|
click_button class: 'gl-dropdown-toggle'
|
|
|
|
click_button 'Copy Terraform init command'
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_content("To get access to this terraform state from your local computer, run the following command at the command line.")
|
|
|
|
end
|
|
|
|
end
|
2020-12-08 22:09:24 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a terraform developer' do
|
|
|
|
let_it_be(:developer) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(developer)
|
|
|
|
gitlab_sign_in(developer)
|
|
|
|
visit project_terraform_index_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user visits the index page' do
|
|
|
|
it 'displays a table without an action dropdown', :aggregate_failures do
|
2020-11-06 07:09:17 -05:00
|
|
|
expect(page).to have_selector(
|
2021-08-12 11:09:58 -04:00
|
|
|
"[data-testid='terraform-states-table-name']",
|
2020-11-06 07:09:17 -05:00
|
|
|
count: project.terraform_states.size
|
|
|
|
)
|
|
|
|
|
2021-08-12 11:09:58 -04:00
|
|
|
expect(page).not_to have_selector("[data-testid*='terraform-state-actions']")
|
2020-11-06 07:09:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|