Commit 7d673308 authored by Reuben Pereira's avatar Reuben Pereira Committed by Rémy Coutable

Refactor environments controller spec

- Now that we've separated the logs HTML and JSON format responses
into 2 APIs, refactor the specs to reflect this.
parent 59371992
...@@ -81,25 +81,6 @@ describe Projects::EnvironmentsController do ...@@ -81,25 +81,6 @@ describe Projects::EnvironmentsController do
before do before do
stub_licensed_features(pod_logs: true) stub_licensed_features(pod_logs: true)
create(:cluster, :provided_by_gcp,
environment_scope: '*', projects: [project])
create(:deployment, :success, environment: environment)
allow_any_instance_of(Gitlab::Kubernetes::RolloutStatus).to receive(:instances)
.and_return([{ pod_name: pod_name }])
end
shared_examples 'resource not found' do |message|
it 'returns 400' do
get :k8s_pod_logs, params: environment_params(pod_name: pod_name, format: :json)
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq(message)
expect(json_response['pods']).to match_array([pod_name])
expect(json_response['pod_name']).to eq(pod_name)
expect(json_response['container_name']).to eq(container)
end
end end
context 'when unlicensed' do context 'when unlicensed' do
...@@ -122,8 +103,10 @@ describe Projects::EnvironmentsController do ...@@ -122,8 +103,10 @@ describe Projects::EnvironmentsController do
expect(response).to render_template 'logs' expect(response).to render_template 'logs'
end end
end end
end
context 'when using JSON format' do describe 'GET k8s_pod_logs' do
let(:pod_name) { "foo" }
let(:container) { 'container-1' } let(:container) { 'container-1' }
let(:service_result) do let(:service_result) do
...@@ -138,10 +121,24 @@ describe Projects::EnvironmentsController do ...@@ -138,10 +121,24 @@ describe Projects::EnvironmentsController do
end end
before do before do
stub_licensed_features(pod_logs: true)
allow_any_instance_of(PodLogsService).to receive(:execute).and_return(service_result) allow_any_instance_of(PodLogsService).to receive(:execute).and_return(service_result)
end end
it 'returns the logs for a specific pod' do shared_examples 'resource not found' do |message|
it 'returns 400', :aggregate_failures do
get :k8s_pod_logs, params: environment_params(pod_name: pod_name, format: :json)
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq(message)
expect(json_response['pods']).to match_array([pod_name])
expect(json_response['pod_name']).to eq(pod_name)
expect(json_response['container_name']).to eq(container)
end
end
it 'returns the logs for a specific pod', :aggregate_failures do
get :k8s_pod_logs, params: environment_params(pod_name: pod_name, format: :json) get :k8s_pod_logs, params: environment_params(pod_name: pod_name, format: :json)
expect(response).to have_gitlab_http_status(:success) expect(response).to have_gitlab_http_status(:success)
...@@ -222,7 +219,6 @@ describe Projects::EnvironmentsController do ...@@ -222,7 +219,6 @@ describe Projects::EnvironmentsController do
end end
end end
end end
end
describe '#GET terminal' do describe '#GET terminal' do
let(:protected_environment) { create(:protected_environment, name: environment.name, project: project) } let(:protected_environment) { create(:protected_environment, name: environment.name, project: project) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment