Commit 16561244 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'ak/specs' into 'master'

Add suggested specs on developper access to logs

See merge request gitlab-org/gitlab!31915
parents 7a56ef68 ed0395e8
......@@ -18,41 +18,53 @@ describe Clusters::EnvironmentEntity do
subject { described_class.new(environment, request: request).as_json }
before do
group.add_maintainer(user)
end
context 'deploy board available' do
context 'with maintainer access' do
before do
allow(group).to receive(:feature_available?).and_call_original
allow(group).to receive(:feature_available?).with(:cluster_deployments).and_return(true)
group.add_maintainer(user)
end
it 'matches expected schema' do
expect(subject.with_indifferent_access).to match_schema('clusters/environment', dir: 'ee')
end
context 'deploy board available' do
before do
allow(group).to receive(:feature_available?).and_call_original
allow(group).to receive(:feature_available?).with(:cluster_deployments).and_return(true)
end
it 'exposes rollout_status' do
expect(subject).to include(:rollout_status)
end
end
it 'matches expected schema' do
expect(subject.with_indifferent_access).to match_schema('clusters/environment', dir: 'ee')
end
context 'deploy board not available' do
before do
allow(group).to receive(:feature_available?).with(:cluster_deployments).and_return(false)
it 'exposes rollout_status' do
expect(subject).to include(:rollout_status)
end
end
it 'matches expected schema' do
expect(subject.with_indifferent_access).to match_schema('clusters/environment', dir: 'ee')
context 'deploy board not available' do
before do
allow(group).to receive(:feature_available?).with(:cluster_deployments).and_return(false)
end
it 'matches expected schema' do
expect(subject.with_indifferent_access).to match_schema('clusters/environment', dir: 'ee')
end
it 'does not expose rollout_status' do
expect(subject).not_to include(:rollout_status)
end
end
it 'does not expose rollout_status' do
expect(subject).not_to include(:rollout_status)
it 'exposes logs_path' do
expect(subject).to include(:logs_path)
end
end
it 'exposes logs_path' do
expect(subject).to include(:logs_path)
context 'with developer access' do
before do
group.add_developer(user)
end
it 'does not expose logs_path' do
expect(subject).not_to include(:logs_path)
end
end
end
end
......@@ -16,16 +16,23 @@ describe Projects::LogsController do
let(:container) { 'container-1' }
before do
project.add_maintainer(user)
sign_in(user)
end
describe 'GET #index' do
let(:empty_project) { create(:project) }
it 'returns 404 with developer access' do
project.add_developer(user)
get :index, params: environment_params
expect(response).to have_gitlab_http_status(:not_found)
end
it 'renders empty logs page if no environment exists' do
empty_project.add_maintainer(user)
get :index, params: { namespace_id: empty_project.namespace, project_id: empty_project }
expect(response).to be_ok
......@@ -33,6 +40,8 @@ describe Projects::LogsController do
end
it 'renders index template' do
project.add_maintainer(user)
get :index, params: environment_params
expect(response).to be_ok
......@@ -60,70 +69,84 @@ describe Projects::LogsController do
end
end
it 'returns the service result' do
it 'returns 404 with developer access' do
project.add_developer(user)
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
expect(response).to have_gitlab_http_status(:success)
expect(json_response).to eq(service_result_json)
expect(response).to have_gitlab_http_status(:not_found)
end
it 'registers a usage of the endpoint' do
expect(::Gitlab::UsageCounters::PodLogs).to receive(:increment).with(project.id)
context 'with maintainer access' do
before do
project.add_maintainer(user)
end
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
it 'returns the service result' do
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
expect(response).to have_gitlab_http_status(:success)
end
expect(response).to have_gitlab_http_status(:success)
expect(json_response).to eq(service_result_json)
end
it 'sets the polling header' do
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
it 'registers a usage of the endpoint' do
expect(::Gitlab::UsageCounters::PodLogs).to receive(:increment).with(project.id)
expect(response).to have_gitlab_http_status(:success)
expect(response.headers['Poll-Interval']).to eq('3000')
end
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
context 'when service is processing' do
let(:service_result) { nil }
expect(response).to have_gitlab_http_status(:success)
end
it 'returns a 202' do
it 'sets the polling header' do
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
expect(response).to have_gitlab_http_status(:accepted)
expect(response).to have_gitlab_http_status(:success)
expect(response.headers['Poll-Interval']).to eq('3000')
end
end
shared_examples 'unsuccessful execution response' do |message|
let(:service_result) do
{
status: :error,
message: message
}
end
context 'when service is processing' do
let(:service_result) { nil }
it 'returns the error' do
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
it 'returns a 202' do
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response).to eq(service_result_json)
expect(response).to have_gitlab_http_status(:accepted)
end
end
end
context 'when service is failing' do
it_behaves_like 'unsuccessful execution response', 'some error'
end
shared_examples 'unsuccessful execution response' do |message|
let(:service_result) do
{
status: :error,
message: message
}
end
context 'when cluster is nil' do
let!(:cluster) { nil }
it 'returns the error' do
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
it_behaves_like 'unsuccessful execution response', 'Environment does not have deployments'
end
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response).to eq(service_result_json)
end
end
context 'when namespace is empty' do
before do
allow(environment).to receive(:deployment_namespace).and_return('')
context 'when service is failing' do
it_behaves_like 'unsuccessful execution response', 'some error'
end
context 'when cluster is nil' do
let!(:cluster) { nil }
it_behaves_like 'unsuccessful execution response', 'Environment does not have deployments'
end
it_behaves_like 'unsuccessful execution response', 'Environment does not have deployments'
context 'when namespace is empty' do
before do
allow(environment).to receive(:deployment_namespace).and_return('')
end
it_behaves_like 'unsuccessful execution response', 'Environment does not have deployments'
end
end
end
......
......@@ -10,7 +10,13 @@ describe EnvironmentEntity do
described_class.new(environment, request: spy('request'))
end
let(:environment) { create(:environment) }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:environment) { create(:environment, project: project) }
before do
allow(entity).to receive(:current_user).and_return(user)
end
subject { entity.as_json }
......@@ -67,28 +73,48 @@ describe EnvironmentEntity do
end
context 'with auto_stop_in' do
let(:environment) { create(:environment, :will_auto_stop) }
let(:environment) { create(:environment, :will_auto_stop, project: project) }
it 'exposes auto stop related information' do
project.add_maintainer(user)
expect(subject).to include(:cancel_auto_stop_path, :auto_stop_at)
end
end
context 'pod_logs' do
it 'exposes logs keys' do
expect(subject).to include(:logs_path)
expect(subject).to include(:logs_api_path)
expect(subject).to include(:enable_advanced_logs_querying)
end
context 'with developer access' do
before do
project.add_developer(user)
end
it 'uses k8s api when ES is not available' do
expect(subject[:logs_api_path]).to eq(k8s_project_logs_path(environment.project, environment_name: environment.name, format: :json))
it 'does not expose logs keys' do
expect(subject).not_to include(:logs_path)
expect(subject).not_to include(:logs_api_path)
expect(subject).not_to include(:enable_advanced_logs_querying)
end
end
it 'uses ES api when ES is available' do
allow(environment).to receive(:elastic_stack_available?).and_return(true)
context 'with maintainer access' do
before do
project.add_maintainer(user)
end
it 'exposes logs keys' do
expect(subject).to include(:logs_path)
expect(subject).to include(:logs_api_path)
expect(subject).to include(:enable_advanced_logs_querying)
end
expect(subject[:logs_api_path]).to eq(elasticsearch_project_logs_path(environment.project, environment_name: environment.name, format: :json))
it 'uses k8s api when ES is not available' do
expect(subject[:logs_api_path]).to eq(k8s_project_logs_path(project, environment_name: environment.name, format: :json))
end
it 'uses ES api when ES is available' do
allow(environment).to receive(:elastic_stack_available?).and_return(true)
expect(subject[:logs_api_path]).to eq(elasticsearch_project_logs_path(project, environment_name: environment.name, format: :json))
end
end
end
end
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