diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-11 21:08:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-11 21:08:58 +0300 |
commit | 1ca9950d5f890cd8f185e1eda158b969a7244fe2 (patch) | |
tree | 6f62715938a4b2b001705c51c697609a8e0850ae /spec/controllers | |
parent | bcc77054ee9aefd1e332e04a4189390fd5a3112e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
3 files changed, 100 insertions, 23 deletions
diff --git a/spec/controllers/admin/services_controller_spec.rb b/spec/controllers/admin/services_controller_spec.rb index 6f59a5ac016..44233776865 100644 --- a/spec/controllers/admin/services_controller_spec.rb +++ b/spec/controllers/admin/services_controller_spec.rb @@ -15,11 +15,11 @@ describe Admin::ServicesController do Service.available_services_names.each do |service_name| context "#{service_name}" do let!(:service) do - service_instance = "#{service_name}_service".camelize.constantize - service_instance.where(instance: true).first_or_create + service_template = "#{service_name}_service".camelize.constantize + service_template.where(template: true).first_or_create end - it 'successfully displays the service' do + it 'successfully displays the template' do get :edit, params: { id: service.id } expect(response).to have_gitlab_http_status(:ok) @@ -34,7 +34,7 @@ describe Admin::ServicesController do RedmineService.create( project: project, active: false, - instance: true, + template: true, properties: { project_url: 'http://abc', issues_url: 'http://abc', @@ -44,7 +44,7 @@ describe Admin::ServicesController do end it 'calls the propagation worker when service is active' do - expect(PropagateInstanceLevelServiceWorker).to receive(:perform_async).with(service.id) + expect(PropagateServiceTemplateWorker).to receive(:perform_async).with(service.id) put :update, params: { id: service.id, service: { active: true } } @@ -52,7 +52,7 @@ describe Admin::ServicesController do end it 'does not call the propagation worker when service is not active' do - expect(PropagateInstanceLevelServiceWorker).not_to receive(:perform_async) + expect(PropagateServiceTemplateWorker).not_to receive(:perform_async) put :update, params: { id: service.id, service: { properties: {} } } diff --git a/spec/controllers/projects/serverless/functions_controller_spec.rb b/spec/controllers/projects/serverless/functions_controller_spec.rb index f0153ac37bf..db7533eb609 100644 --- a/spec/controllers/projects/serverless/functions_controller_spec.rb +++ b/spec/controllers/projects/serverless/functions_controller_spec.rb @@ -14,9 +14,11 @@ describe Projects::Serverless::FunctionsController do let!(:deployment) { create(:deployment, :success, environment: environment, cluster: cluster) } let(:knative_services_finder) { environment.knative_services_finder } let(:function_description) { 'A serverless function' } + let(:function_name) { 'some-function-name' } let(:knative_stub_options) do - { namespace: namespace.namespace, name: cluster.project.name, description: function_description } + { namespace: namespace.namespace, name: function_name, description: function_description } end + let(:knative) { create(:clusters_applications_knative, :installed, cluster: cluster) } let(:namespace) do create(:cluster_kubernetes_namespace, @@ -87,25 +89,65 @@ describe Projects::Serverless::FunctionsController do end context 'when functions were found' do - let(:functions) { ["asdf"] } + let(:functions) { [{}, {}] } before do - stub_kubeclient_knative_services(namespace: namespace.namespace) - get :index, params: params({ format: :json }) + stub_kubeclient_knative_services(namespace: namespace.namespace, cluster_id: cluster.id, name: function_name) end it 'returns functions' do + get :index, params: params({ format: :json }) expect(json_response["functions"]).not_to be_empty end - it { expect(response).to have_gitlab_http_status(:ok) } + it 'filters out the functions whose cluster the user does not have permission to read' do + allow(controller).to receive(:can?).and_return(true) + expect(controller).to receive(:can?).with(user, :read_cluster, cluster).and_return(false) + + get :index, params: params({ format: :json }) + + expect(json_response["functions"]).to be_empty + end + + it 'returns a successful response status' do + get :index, params: params({ format: :json }) + expect(response).to have_gitlab_http_status(:ok) + end + + context 'when there is serverless domain for a cluster' do + let!(:serverless_domain_cluster) do + create(:serverless_domain_cluster, clusters_applications_knative_id: knative.id) + end + + it 'returns JSON with function details with serverless domain URL' do + get :index, params: params({ format: :json }) + expect(response).to have_gitlab_http_status(:ok) + + expect(json_response["functions"]).not_to be_empty + + expect(json_response["functions"]).to all( + include( + 'url' => "https://#{function_name}-#{serverless_domain_cluster.uuid[0..1]}a1#{serverless_domain_cluster.uuid[2..-3]}f2#{serverless_domain_cluster.uuid[-2..-1]}#{"%x" % environment.id}-#{environment.slug}.#{serverless_domain_cluster.domain}" + ) + ) + end + end + + context 'when there is no serverless domain for a cluster' do + it 'keeps function URL as it was' do + expect(Gitlab::Serverless::Domain).not_to receive(:new) + + get :index, params: params({ format: :json }) + expect(response).to have_gitlab_http_status(:ok) + end + end end end end describe 'GET #show' do - context 'invalid data' do - it 'has a bad function name' do + context 'with function that does not exist' do + it 'returns 404' do get :show, params: params({ format: :json, environment_id: "*", id: "foo" }) expect(response).to have_gitlab_http_status(:not_found) end @@ -113,15 +155,50 @@ describe Projects::Serverless::FunctionsController do context 'with valid data', :use_clean_rails_memory_store_caching do shared_examples 'GET #show with valid data' do - it 'has a valid function name' do - get :show, params: params({ format: :json, environment_id: "*", id: cluster.project.name }) + context 'when there is serverless domain for a cluster' do + let!(:serverless_domain_cluster) do + create(:serverless_domain_cluster, clusters_applications_knative_id: knative.id) + end + + it 'returns JSON with function details with serverless domain URL' do + get :show, params: params({ format: :json, environment_id: "*", id: function_name }) + expect(response).to have_gitlab_http_status(:ok) + + expect(json_response).to include( + 'url' => "https://#{function_name}-#{serverless_domain_cluster.uuid[0..1]}a1#{serverless_domain_cluster.uuid[2..-3]}f2#{serverless_domain_cluster.uuid[-2..-1]}#{"%x" % environment.id}-#{environment.slug}.#{serverless_domain_cluster.domain}" + ) + end + + it 'returns 404 when user does not have permission to read the cluster' do + allow(controller).to receive(:can?).and_return(true) + expect(controller).to receive(:can?).with(user, :read_cluster, cluster).and_return(false) + + get :show, params: params({ format: :json, environment_id: "*", id: function_name }) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'when there is no serverless domain for a cluster' do + it 'keeps function URL as it was' do + get :show, params: params({ format: :json, environment_id: "*", id: function_name }) + expect(response).to have_gitlab_http_status(:ok) + + expect(json_response).to include( + 'url' => "http://#{function_name}.#{namespace.namespace}.example.com" + ) + end + end + + it 'return json with function details' do + get :show, params: params({ format: :json, environment_id: "*", id: function_name }) expect(response).to have_gitlab_http_status(:ok) expect(json_response).to include( - 'name' => project.name, - 'url' => "http://#{project.name}.#{namespace.namespace}.example.com", + 'name' => function_name, + 'url' => "http://#{function_name}.#{namespace.namespace}.example.com", 'description' => function_description, - 'podcount' => 1 + 'podcount' => 0 ) end end @@ -180,8 +257,8 @@ describe Projects::Serverless::FunctionsController do 'knative_installed' => 'checking', 'functions' => [ a_hash_including( - 'name' => project.name, - 'url' => "http://#{project.name}.#{namespace.namespace}.example.com", + 'name' => function_name, + 'url' => "http://#{function_name}.#{namespace.namespace}.example.com", 'description' => function_description ) ] diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb index b6c64a964a6..fb7cca3997b 100644 --- a/spec/controllers/projects/services_controller_spec.rb +++ b/spec/controllers/projects/services_controller_spec.rb @@ -154,12 +154,12 @@ describe Projects::ServicesController do end end - context 'when activating Jira service from instance level service' do + context 'when activating Jira service from a template' do let(:service) do - create(:jira_service, project: project, instance: true) + create(:jira_service, project: project, template: true) end - it 'activate Jira service from instance level service' do + it 'activate Jira service from template' do expect(flash[:notice]).to eq 'Jira activated.' end end |