2019-05-23 14:07:59 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-05 10:58:05 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'Clusters', :js do
|
2017-10-31 14:59:40 -04:00
|
|
|
include GoogleApi::CloudPlatformHelpers
|
|
|
|
|
2017-12-03 15:34:00 -05:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:user) { create(:user) }
|
2017-10-05 10:58:05 -04:00
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-10-05 10:58:05 -04:00
|
|
|
gitlab_sign_in(user)
|
2020-03-04 01:08:23 -05:00
|
|
|
stub_feature_flags(clusters_list_redesign: false)
|
2017-10-05 10:58:05 -04:00
|
|
|
end
|
|
|
|
|
2017-12-03 15:34:00 -05:00
|
|
|
context 'when user does not have a cluster and visits cluster index page' do
|
2017-10-05 10:58:05 -04:00
|
|
|
before do
|
|
|
|
visit project_clusters_path(project)
|
|
|
|
end
|
|
|
|
|
2017-12-03 16:55:32 -05:00
|
|
|
it 'sees empty state' do
|
2018-01-29 14:49:00 -05:00
|
|
|
expect(page).to have_link('Add Kubernetes cluster')
|
2017-12-03 16:55:32 -05:00
|
|
|
expect(page).to have_selector('.empty-state')
|
2017-10-05 10:58:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-08 08:09:33 -04:00
|
|
|
context 'when user has a cluster' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Clusters::Cluster).to receive(:retrieve_connection_status).and_return(:connected)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user adds an existing cluster' do
|
|
|
|
before do
|
|
|
|
create(:cluster, :provided_by_user, name: 'default-cluster', environment_scope: '*', projects: [project])
|
|
|
|
visit project_clusters_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'user sees an add cluster button' do
|
|
|
|
expect(page).to have_selector('.js-add-cluster:not(.readonly)')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user filled form with environment scope' do
|
|
|
|
before do
|
|
|
|
click_link 'Add Kubernetes cluster'
|
2020-08-28 11:10:21 -04:00
|
|
|
click_link 'Connect existing cluster'
|
2020-07-08 08:09:33 -04:00
|
|
|
fill_in 'cluster_name', with: 'staging-cluster'
|
|
|
|
fill_in 'cluster_environment_scope', with: 'staging/*'
|
|
|
|
click_button 'Add Kubernetes cluster'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'user sees a cluster details page' do
|
|
|
|
expect(page.find_field('cluster[name]').value).to eq('staging-cluster')
|
|
|
|
expect(page.find_field('cluster[environment_scope]').value).to eq('staging/*')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user updates environment scope' do
|
|
|
|
before do
|
|
|
|
click_link 'default-cluster'
|
|
|
|
fill_in 'cluster_environment_scope', with: 'production/*'
|
|
|
|
within '.js-cluster-integration-form' do
|
|
|
|
click_button 'Save changes'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the environment scope' do
|
|
|
|
expect(page.find_field('cluster[environment_scope]').value).to eq('production/*')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user updates duplicated environment scope' do
|
|
|
|
before do
|
|
|
|
click_link 'Add Kubernetes cluster'
|
2020-08-28 11:10:21 -04:00
|
|
|
click_link 'Connect existing cluster'
|
2020-07-08 08:09:33 -04:00
|
|
|
fill_in 'cluster_name', with: 'staging-cluster'
|
|
|
|
fill_in 'cluster_environment_scope', with: '*'
|
|
|
|
fill_in 'cluster_platform_kubernetes_attributes_api_url', with: 'https://0.0.0.0'
|
|
|
|
fill_in 'cluster_platform_kubernetes_attributes_token', with: 'token'
|
|
|
|
|
|
|
|
click_button 'Add Kubernetes cluster'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'users sees an environment scope validation error' do
|
|
|
|
expect(page).to have_content('cannot add duplicated environment scope')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user adds a Google Kubernetes Engine cluster' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Projects::ClustersController)
|
|
|
|
.to receive(:token_in_session).and_return('token')
|
|
|
|
allow_any_instance_of(Projects::ClustersController)
|
|
|
|
.to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s)
|
|
|
|
|
|
|
|
allow_any_instance_of(Projects::ClustersController).to receive(:authorize_google_project_billing)
|
|
|
|
allow_any_instance_of(Projects::ClustersController).to receive(:google_project_billing_status).and_return(true)
|
|
|
|
|
|
|
|
allow_any_instance_of(GoogleApi::CloudPlatform::Client)
|
|
|
|
.to receive(:projects_zones_clusters_create) do
|
|
|
|
OpenStruct.new(
|
|
|
|
self_link: 'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123',
|
|
|
|
status: 'RUNNING'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
allow(WaitForClusterCreationWorker).to receive(:perform_in).and_return(nil)
|
|
|
|
|
|
|
|
create(:cluster, :provided_by_gcp, name: 'default-cluster', environment_scope: '*', projects: [project])
|
|
|
|
visit project_clusters_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'user sees a add cluster button ' do
|
|
|
|
expect(page).to have_selector('.js-add-cluster:not(.readonly)')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user filled form with environment scope' do
|
|
|
|
before do
|
|
|
|
click_link 'Add Kubernetes cluster'
|
|
|
|
click_link 'Create new cluster'
|
|
|
|
click_link 'Google GKE'
|
|
|
|
|
|
|
|
sleep 2 # wait for ajax
|
|
|
|
execute_script('document.querySelector(".js-gcp-project-id-dropdown input").setAttribute("type", "text")')
|
|
|
|
execute_script('document.querySelector(".js-gcp-zone-dropdown input").setAttribute("type", "text")')
|
|
|
|
execute_script('document.querySelector(".js-gcp-machine-type-dropdown input").setAttribute("type", "text")')
|
|
|
|
execute_script('document.querySelector(".js-gke-cluster-creation-submit").removeAttribute("disabled")')
|
|
|
|
|
|
|
|
fill_in 'cluster_name', with: 'staging-cluster'
|
|
|
|
fill_in 'cluster_environment_scope', with: 'staging/*'
|
|
|
|
fill_in 'cluster[provider_gcp_attributes][gcp_project_id]', with: 'gcp-project-123'
|
|
|
|
fill_in 'cluster[provider_gcp_attributes][zone]', with: 'us-central1-a'
|
|
|
|
fill_in 'cluster[provider_gcp_attributes][machine_type]', with: 'n1-standard-2'
|
|
|
|
click_button 'Create Kubernetes cluster'
|
|
|
|
|
|
|
|
# The frontend won't show the details until the cluster is
|
|
|
|
# created, and we don't want to make calls out to GCP.
|
|
|
|
provider = Clusters::Cluster.last.provider
|
|
|
|
provider.make_created
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'user sees a cluster details page' do
|
|
|
|
expect(page).to have_content('GitLab Integration')
|
|
|
|
expect(page.find_field('cluster[environment_scope]').value).to eq('staging/*')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user updates environment scope' do
|
|
|
|
before do
|
|
|
|
click_link 'default-cluster'
|
|
|
|
fill_in 'cluster_environment_scope', with: 'production/*'
|
|
|
|
within ".js-cluster-integration-form" do
|
|
|
|
click_button 'Save changes'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the environment scope' do
|
|
|
|
expect(page.find_field('cluster[environment_scope]').value).to eq('production/*')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user updates duplicated environment scope' do
|
|
|
|
before do
|
|
|
|
click_link 'Add Kubernetes cluster'
|
|
|
|
click_link 'Create new cluster'
|
|
|
|
click_link 'Google GKE'
|
|
|
|
|
|
|
|
sleep 2 # wait for ajax
|
|
|
|
execute_script('document.querySelector(".js-gcp-project-id-dropdown input").setAttribute("type", "text")')
|
|
|
|
execute_script('document.querySelector(".js-gcp-zone-dropdown input").setAttribute("type", "text")')
|
|
|
|
execute_script('document.querySelector(".js-gcp-machine-type-dropdown input").setAttribute("type", "text")')
|
|
|
|
execute_script('document.querySelector(".js-gke-cluster-creation-submit").removeAttribute("disabled")')
|
|
|
|
|
|
|
|
fill_in 'cluster_name', with: 'staging-cluster'
|
|
|
|
fill_in 'cluster_environment_scope', with: '*'
|
|
|
|
fill_in 'cluster[provider_gcp_attributes][gcp_project_id]', with: 'gcp-project-123'
|
|
|
|
fill_in 'cluster[provider_gcp_attributes][zone]', with: 'us-central1-a'
|
|
|
|
fill_in 'cluster[provider_gcp_attributes][machine_type]', with: 'n1-standard-2'
|
|
|
|
click_button 'Create Kubernetes cluster'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'users sees an environment scope validation error' do
|
|
|
|
expect(page).to have_content('cannot add duplicated environment scope')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-03 16:55:32 -05:00
|
|
|
context 'when user has a cluster and visits cluster index page' do
|
|
|
|
let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
|
|
|
|
let(:project) { cluster.project }
|
2017-11-07 11:22:28 -05:00
|
|
|
|
2017-12-03 16:55:32 -05:00
|
|
|
before do
|
|
|
|
visit project_clusters_path(project)
|
|
|
|
end
|
2017-10-05 10:58:05 -04:00
|
|
|
|
2017-12-03 16:55:32 -05:00
|
|
|
it 'user sees a table with one cluster' do
|
|
|
|
# One is the header row, the other the cluster row
|
|
|
|
expect(page).to have_selector('.gl-responsive-table-row', count: 2)
|
|
|
|
end
|
2017-11-07 11:22:28 -05:00
|
|
|
|
2017-12-03 16:55:32 -05:00
|
|
|
context 'when user clicks on a cluster' do
|
2017-10-05 10:58:05 -04:00
|
|
|
before do
|
2017-12-03 16:55:32 -05:00
|
|
|
click_link cluster.name
|
2017-10-05 10:58:05 -04:00
|
|
|
end
|
|
|
|
|
2017-12-03 16:55:32 -05:00
|
|
|
it 'user sees a cluster details page' do
|
2017-10-06 10:14:14 -04:00
|
|
|
expect(page).to have_button('Save')
|
2017-10-31 14:59:40 -04:00
|
|
|
expect(page.find(:css, '.cluster-name').value).to eq(cluster.name)
|
2017-10-05 10:58:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-26 19:06:23 -05:00
|
|
|
context 'user visits create cluster page' do
|
2017-10-05 10:58:05 -04:00
|
|
|
before do
|
|
|
|
visit project_clusters_path(project)
|
2017-11-01 10:13:22 -04:00
|
|
|
|
2018-01-29 14:49:00 -05:00
|
|
|
click_link 'Add Kubernetes cluster'
|
2019-12-17 19:08:09 -05:00
|
|
|
click_link 'Create new cluster'
|
2017-10-05 10:58:05 -04:00
|
|
|
end
|
|
|
|
|
2019-11-26 19:06:23 -05:00
|
|
|
it 'user sees a link to create a GKE cluster' do
|
|
|
|
expect(page).to have_link('Google GKE')
|
2017-10-05 10:58:05 -04:00
|
|
|
end
|
2019-09-09 16:27:51 -04:00
|
|
|
|
2019-11-26 19:06:23 -05:00
|
|
|
it 'user sees a link to create an EKS cluster' do
|
|
|
|
expect(page).to have_link('Amazon EKS')
|
2019-09-09 16:27:51 -04:00
|
|
|
end
|
|
|
|
end
|
2017-10-05 10:58:05 -04:00
|
|
|
end
|