diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-31 18:07:53 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-31 18:07:53 +0300 |
commit | d7a028e20d29b8c6d0e780ac168544dfbb712d3c (patch) | |
tree | f9fc9ea12e166aec6c4ffe476ba7a3566396b696 /spec/requests/api/project_clusters_spec.rb | |
parent | 0d0cddc9ce20c5a7d8a2723d0aa620ca184a711a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/api/project_clusters_spec.rb')
-rw-r--r-- | spec/requests/api/project_clusters_spec.rb | 80 |
1 files changed, 26 insertions, 54 deletions
diff --git a/spec/requests/api/project_clusters_spec.rb b/spec/requests/api/project_clusters_spec.rb index 7cef40ff3b5..648577dce8d 100644 --- a/spec/requests/api/project_clusters_spec.rb +++ b/spec/requests/api/project_clusters_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' describe API::ProjectClusters do include KubernetesHelpers - let(:current_user) { create(:user) } - let(:developer_user) { create(:user) } - let(:project) { create(:project) } + let_it_be(:current_user) { create(:user) } + let_it_be(:developer_user) { create(:user) } + let_it_be(:project) { create(:project) } before do project.add_maintainer(current_user) @@ -15,10 +15,10 @@ describe API::ProjectClusters do end describe 'GET /projects/:id/clusters' do - let!(:extra_cluster) { create(:cluster, :provided_by_gcp, :project) } + let_it_be(:extra_cluster) { create(:cluster, :provided_by_gcp, :project) } - let!(:clusters) do - create_list(:cluster, 5, :provided_by_gcp, :project, :production_environment, + let_it_be(:clusters) do + create_list(:cluster, 2, :provided_by_gcp, :project, :production_environment, projects: [project]) end @@ -35,17 +35,15 @@ describe API::ProjectClusters do get api("/projects/#{project.id}/clusters", current_user) end - it 'responds with 200' do - expect(response).to have_gitlab_http_status(:ok) - end - it 'includes pagination headers' do + expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers end it 'onlies include authorized clusters' do cluster_ids = json_response.map { |cluster| cluster['id'] } + expect(response).to have_gitlab_http_status(:ok) expect(cluster_ids).to match_array(clusters.pluck(:id)) expect(cluster_ids).not_to include(extra_cluster.id) end @@ -139,7 +137,7 @@ describe API::ProjectClusters do end context 'with non-existing cluster' do - let(:cluster_id) { 123 } + let(:cluster_id) { 0 } it 'returns 404' do expect(response).to have_gitlab_http_status(:not_found) @@ -185,14 +183,11 @@ describe API::ProjectClusters do end context 'with valid params' do - it 'responds with 201' do - expect(response).to have_gitlab_http_status(:created) - end - it 'creates a new Cluster::Cluster' do cluster_result = Clusters::Cluster.find(json_response["id"]) platform_kubernetes = cluster_result.platform + expect(response).to have_gitlab_http_status(:created) expect(cluster_result).to be_user expect(cluster_result).to be_kubernetes expect(cluster_result.project).to eq(project) @@ -235,15 +230,9 @@ describe API::ProjectClusters do context 'with invalid params' do let(:namespace) { 'invalid_namespace' } - it 'responds with 400' do - expect(response).to have_gitlab_http_status(:bad_request) - end - it 'does not create a new Clusters::Cluster' do + expect(response).to have_gitlab_http_status(:bad_request) expect(project.reload.clusters).to be_empty - end - - it 'returns validation errors' do expect(json_response['message']['platform_kubernetes.namespace'].first).to be_present end end @@ -259,8 +248,8 @@ describe API::ProjectClusters do it 'responds with 400' do expect(response).to have_gitlab_http_status(:bad_request) - - expect(json_response['message']['base'].first).to eq(_('Instance does not support multiple Kubernetes clusters')) + expect(json_response['message']['base'].first) + .to eq(_('Instance does not support multiple Kubernetes clusters')) end end @@ -271,7 +260,6 @@ describe API::ProjectClusters do it 'responds with 403' do expect(response).to have_gitlab_http_status(:forbidden) - expect(json_response['message']).to eq('403 Forbidden') end end @@ -281,7 +269,7 @@ describe API::ProjectClusters do let(:api_url) { 'https://kubernetes.example.com' } let(:namespace) { 'new-namespace' } let(:platform_kubernetes_attributes) { { namespace: namespace } } - let(:management_project) { create(:project, namespace: project.namespace) } + let_it_be(:management_project) { create(:project, namespace: project.namespace) } let(:management_project_id) { management_project.id } let(:update_params) do @@ -321,11 +309,8 @@ describe API::ProjectClusters do end context 'with valid params' do - it 'responds with 200' do - expect(response).to have_gitlab_http_status(:ok) - end - it 'updates cluster attributes' do + expect(response).to have_gitlab_http_status(:ok) expect(cluster.domain).to eq('new-domain.com') expect(cluster.platform_kubernetes.namespace).to eq('new-namespace') expect(cluster.management_project).to eq(management_project) @@ -335,29 +320,24 @@ describe API::ProjectClusters do context 'with invalid params' do let(:namespace) { 'invalid_namespace' } - it 'responds with 400' do - expect(response).to have_gitlab_http_status(:bad_request) - end - it 'does not update cluster attributes' do + expect(response).to have_gitlab_http_status(:bad_request) expect(cluster.domain).not_to eq('new_domain.com') expect(cluster.platform_kubernetes.namespace).not_to eq('invalid_namespace') expect(cluster.management_project).not_to eq(management_project) end it 'returns validation errors' do - expect(json_response['message']['platform_kubernetes.namespace'].first).to match('can contain only lowercase letters') + expect(json_response['message']['platform_kubernetes.namespace'].first) + .to match('can contain only lowercase letters') end end context 'current user does not have access to management_project_id' do - let(:management_project_id) { create(:project).id } - - it 'responds with 400' do - expect(response).to have_gitlab_http_status(:bad_request) - end + let_it_be(:management_project_id) { create(:project).id } it 'returns validation errors' do + expect(response).to have_gitlab_http_status(:bad_request) expect(json_response['message']['management_project_id'].first).to match('don\'t have permission') end end @@ -371,12 +351,10 @@ describe API::ProjectClusters do } end - it 'responds with 400' do - expect(response).to have_gitlab_http_status(:bad_request) - end - it 'returns validation error' do - expect(json_response['message']['platform_kubernetes.base'].first).to eq(_('Cannot modify managed Kubernetes cluster')) + expect(response).to have_gitlab_http_status(:bad_request) + expect(json_response['message']['platform_kubernetes.base'].first) + .to eq(_('Cannot modify managed Kubernetes cluster')) end end @@ -412,13 +390,10 @@ describe API::ProjectClusters do } end - it 'responds with 200' do - expect(response).to have_gitlab_http_status(:ok) - end - it 'updates platform kubernetes attributes' do platform_kubernetes = cluster.platform_kubernetes + expect(response).to have_gitlab_http_status(:ok) expect(cluster.name).to eq('new-name') expect(platform_kubernetes.namespace).to eq('new-namespace') expect(platform_kubernetes.api_url).to eq('https://new-api-url.com') @@ -439,7 +414,7 @@ describe API::ProjectClusters do describe 'DELETE /projects/:id/clusters/:cluster_id' do let(:cluster_params) { { cluster_id: cluster.id } } - let(:cluster) do + let_it_be(:cluster) do create(:cluster, :project, :provided_by_gcp, projects: [project]) end @@ -457,11 +432,8 @@ describe API::ProjectClusters do delete api("/projects/#{project.id}/clusters/#{cluster.id}", current_user), params: cluster_params end - it 'responds with 204' do - expect(response).to have_gitlab_http_status(:no_content) - end - it 'deletes the cluster' do + expect(response).to have_gitlab_http_status(:no_content) expect(Clusters::Cluster.exists?(id: cluster.id)).to be_falsy end |