2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec . describe ClustersHelper do
2019-07-07 11:18:12 +05:30
describe '#has_rbac_enabled?' do
context 'when kubernetes platform has been created' do
let ( :platform_kubernetes ) { build_stubbed ( :cluster_platform_kubernetes ) }
let ( :cluster ) { build_stubbed ( :cluster , :provided_by_gcp , platform_kubernetes : platform_kubernetes ) }
it 'returns kubernetes platform value' do
expect ( helper . has_rbac_enabled? ( cluster ) ) . to be_truthy
end
end
context 'when kubernetes platform has not been created yet' do
let ( :cluster ) { build_stubbed ( :cluster , :providing_by_gcp ) }
it 'delegates to cluster provider' do
expect ( helper . has_rbac_enabled? ( cluster ) ) . to be_truthy
end
context 'when ABAC cluster is created' do
let ( :provider ) { build_stubbed ( :cluster_provider_gcp , :abac_enabled ) }
let ( :cluster ) { build_stubbed ( :cluster , :providing_by_gcp , provider_gcp : provider ) }
it 'delegates to cluster provider' do
expect ( helper . has_rbac_enabled? ( cluster ) ) . to be_falsy
end
end
end
end
2019-12-26 22:10:19 +05:30
describe '#create_new_cluster_label' do
subject { helper . create_new_cluster_label ( provider : provider ) }
context 'GCP provider' do
let ( :provider ) { 'gcp' }
2020-01-01 13:55:28 +05:30
it { is_expected . to eq ( 'Create new cluster on GKE' ) }
2019-12-26 22:10:19 +05:30
end
context 'AWS provider' do
let ( :provider ) { 'aws' }
2020-01-01 13:55:28 +05:30
it { is_expected . to eq ( 'Create new cluster on EKS' ) }
2019-12-26 22:10:19 +05:30
end
context 'other provider' do
let ( :provider ) { 'other' }
2020-01-01 13:55:28 +05:30
it { is_expected . to eq ( 'Create new cluster' ) }
2019-12-26 22:10:19 +05:30
end
context 'no provider' do
let ( :provider ) { nil }
2020-01-01 13:55:28 +05:30
it { is_expected . to eq ( 'Create new cluster' ) }
2019-12-26 22:10:19 +05:30
end
end
2020-04-22 19:07:51 +05:30
2021-12-11 22:18:48 +05:30
describe '#js_clusters_list_data' do
let_it_be ( :current_user ) { create ( :user ) }
let_it_be ( :project ) { build ( :project ) }
let_it_be ( :clusterable ) { ClusterablePresenter . fabricate ( project , current_user : current_user ) }
2021-01-03 14:25:43 +05:30
2021-12-11 22:18:48 +05:30
subject { helper . js_clusters_list_data ( clusterable ) }
2021-01-03 14:25:43 +05:30
2021-12-11 22:18:48 +05:30
it 'displays endpoint path' do
expect ( subject [ :endpoint ] ) . to eq ( " #{ project_path ( project ) } /-/clusters.json " )
2021-01-03 14:25:43 +05:30
end
2021-12-11 22:18:48 +05:30
it 'generates svg image data' , :aggregate_failures do
expect ( subject . dig ( :img_tags , :aws , :path ) ) . to match ( %r( /illustrations/logos/amazon_eks|svg ) )
expect ( subject . dig ( :img_tags , :default , :path ) ) . to match ( %r( /illustrations/logos/kubernetes|svg ) )
expect ( subject . dig ( :img_tags , :gcp , :path ) ) . to match ( %r( /illustrations/logos/google_gke|svg ) )
expect ( subject . dig ( :img_tags , :aws , :text ) ) . to eq ( 'Amazon EKS' )
expect ( subject . dig ( :img_tags , :default , :text ) ) . to eq ( 'Kubernetes Cluster' )
expect ( subject . dig ( :img_tags , :gcp , :text ) ) . to eq ( 'Google GKE' )
2021-01-03 14:25:43 +05:30
end
2021-12-11 22:18:48 +05:30
it 'displays and ancestor_help_path' do
expect ( subject [ :ancestor_help_path ] ) . to eq ( help_page_path ( 'user/group/clusters/index' , anchor : 'cluster-precedence' ) )
2021-01-03 14:25:43 +05:30
end
2021-09-30 23:02:18 +05:30
2021-12-11 22:18:48 +05:30
it 'displays empty image path' do
expect ( subject [ :clusters_empty_state_image ] ) . to match ( %r( /illustrations/empty-state/empty-state-clusters|svg ) )
2021-09-30 23:02:18 +05:30
end
2021-10-27 15:23:28 +05:30
2021-12-11 22:18:48 +05:30
it 'displays create cluster using certificate path' do
expect ( subject [ :new_cluster_path ] ) . to eq ( " #{ project_path ( project ) } /-/clusters/new?tab=create " )
end
context 'user has no permissions to create a cluster' do
it 'displays that user can\t add cluster' do
expect ( subject [ :can_add_cluster ] ) . to eq ( " false " )
end
end
context 'user is a maintainer' do
before do
project . add_maintainer ( current_user )
end
it 'displays that the user can add cluster' do
expect ( subject [ :can_add_cluster ] ) . to eq ( " true " )
end
end
context 'project cluster' do
it 'doesn\'t display empty state help text' do
expect ( subject [ :empty_state_help_text ] ) . to be_nil
end
end
context 'group cluster' do
let_it_be ( :group ) { create ( :group ) }
let_it_be ( :clusterable ) { ClusterablePresenter . fabricate ( group , current_user : current_user ) }
it 'displays empty state help text' do
expect ( subject [ :empty_state_help_text ] ) . to eq ( s_ ( 'ClusterIntegration|Adding an integration to your group will share the cluster across all your projects.' ) )
end
2021-10-27 15:23:28 +05:30
end
2021-01-03 14:25:43 +05:30
end
2021-12-11 22:18:48 +05:30
describe '#js_clusters_data' do
let_it_be ( :current_user ) { create ( :user ) }
let_it_be ( :project ) { build ( :project ) }
let_it_be ( :clusterable ) { ClusterablePresenter . fabricate ( project , current_user : current_user ) }
2020-06-23 00:09:42 +05:30
2021-12-11 22:18:48 +05:30
subject { helper . js_clusters_data ( clusterable ) }
it 'displays project default branch' do
expect ( subject [ :default_branch_name ] ) . to eq ( project . default_branch )
2020-07-28 23:09:34 +05:30
end
2021-12-11 22:18:48 +05:30
it 'displays image path' do
expect ( subject [ :empty_state_image ] ) . to match ( %r( /illustrations/empty-state/empty-state-agents|svg ) )
end
2020-06-23 00:09:42 +05:30
2021-12-11 22:18:48 +05:30
it 'displays project path' do
expect ( subject [ :project_path ] ) . to eq ( project . full_path )
2020-07-28 23:09:34 +05:30
end
2020-06-23 00:09:42 +05:30
2021-12-11 22:18:48 +05:30
it 'displays add cluster using certificate path' do
expect ( subject [ :add_cluster_path ] ) . to eq ( " #{ project_path ( project ) } /-/clusters/new?tab=add " )
end
it 'displays kas address' do
expect ( subject [ :kas_address ] ) . to eq ( Gitlab :: Kas . external_url )
2020-11-24 15:15:51 +05:30
end
end
describe '#js_cluster_new' do
subject { helper . js_cluster_new }
it 'displays a cluster_connect_help_path' do
expect ( subject [ :cluster_connect_help_path ] ) . to eq ( help_page_path ( 'user/project/clusters/add_remove_clusters' , anchor : 'add-existing-cluster' ) )
2020-06-23 00:09:42 +05:30
end
end
2020-04-22 19:07:51 +05:30
describe '#cluster_type_label' do
subject { helper . cluster_type_label ( cluster_type ) }
context 'project cluster' do
let ( :cluster_type ) { 'project_type' }
it { is_expected . to eq ( 'Project cluster' ) }
end
context 'group cluster' do
let ( :cluster_type ) { 'group_type' }
it { is_expected . to eq ( 'Group cluster' ) }
end
context 'instance cluster' do
let ( :cluster_type ) { 'instance_type' }
it { is_expected . to eq ( 'Instance cluster' ) }
end
context 'other values' do
let ( :cluster_type ) { 'not_supported' }
2021-02-22 17:27:13 +05:30
it 'diplays generic cluster and reports error' do
2020-04-22 19:07:51 +05:30
expect ( Gitlab :: ErrorTracking ) . to receive ( :track_and_raise_for_dev_exception ) . with (
an_instance_of ( ArgumentError ) ,
cluster_error : { error : 'Cluster Type Missing' , cluster_type : 'not_supported' }
)
is_expected . to eq ( 'Cluster' )
end
end
end
2021-12-11 22:18:48 +05:30
describe '#display_cluster_agents?' do
subject { helper . display_cluster_agents? ( clusterable ) }
context 'when clusterable is a project' do
let ( :clusterable ) { build ( :project ) }
it 'allows agents to display' do
expect ( subject ) . to be_truthy
end
end
context 'when clusterable is a group' do
let ( :clusterable ) { build ( :group ) }
it 'does not allow agents to display' do
expect ( subject ) . to be_falsey
end
end
end
2019-07-07 11:18:12 +05:30
end