summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/ci/lint_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/pipeline/logger_spec.rb20
-rw-r--r--spec/lib/gitlab/gitaly_client/operation_service_spec.rb45
-rw-r--r--spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb16
4 files changed, 55 insertions, 30 deletions
diff --git a/spec/lib/gitlab/ci/lint_spec.rb b/spec/lib/gitlab/ci/lint_spec.rb
index cf07e952f26..cd3d4ee07bb 100644
--- a/spec/lib/gitlab/ci/lint_spec.rb
+++ b/spec/lib/gitlab/ci/lint_spec.rb
@@ -341,10 +341,8 @@ RSpec.describe Gitlab::Ci::Lint do
let(:counters) do
{
'count' => a_kind_of(Numeric),
- 'avg' => a_kind_of(Numeric),
- 'sum' => a_kind_of(Numeric),
'max' => a_kind_of(Numeric),
- 'min' => a_kind_of(Numeric)
+ 'sum' => a_kind_of(Numeric)
}
end
diff --git a/spec/lib/gitlab/ci/pipeline/logger_spec.rb b/spec/lib/gitlab/ci/pipeline/logger_spec.rb
index 3af0ebe7484..049a9a416a0 100644
--- a/spec/lib/gitlab/ci/pipeline/logger_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/logger_spec.rb
@@ -25,10 +25,8 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Logger do
loggable_data = {
'expensive_operation_duration_s' => {
'count' => 1,
- 'sum' => a_kind_of(Numeric),
- 'avg' => a_kind_of(Numeric),
'max' => a_kind_of(Numeric),
- 'min' => a_kind_of(Numeric)
+ 'sum' => a_kind_of(Numeric)
}
}
@@ -62,17 +60,13 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Logger do
data = keys.each.with_object({}) do |key, accumulator|
accumulator[key] = {
'count' => count,
- 'avg' => a_kind_of(Numeric),
- 'sum' => a_kind_of(Numeric),
'max' => a_kind_of(Numeric),
- 'min' => a_kind_of(Numeric)
+ 'sum' => a_kind_of(Numeric)
}
end
if db_count
data['expensive_operation_db_count']['max'] = db_count
- data['expensive_operation_db_count']['min'] = db_count
- data['expensive_operation_db_count']['avg'] = db_count
data['expensive_operation_db_count']['sum'] = count * db_count
end
@@ -134,7 +128,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Logger do
it 'records durations of observed operations' do
loggable_data = {
'pipeline_creation_duration_s' => {
- 'avg' => 30, 'sum' => 30, 'count' => 1, 'max' => 30, 'min' => 30
+ 'sum' => 30, 'count' => 1, 'max' => 30
}
}
@@ -168,10 +162,10 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Logger do
'pipeline_creation_caller' => 'source',
'pipeline_source' => pipeline.source,
'pipeline_save_duration_s' => {
- 'avg' => 60, 'sum' => 60, 'count' => 1, 'max' => 60, 'min' => 60
+ 'sum' => 60, 'count' => 1, 'max' => 60
},
'pipeline_creation_duration_s' => {
- 'avg' => 20, 'sum' => 40, 'count' => 2, 'max' => 30, 'min' => 10
+ 'sum' => 40, 'count' => 2, 'max' => 30
}
}
end
@@ -218,10 +212,10 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Logger do
'pipeline_creation_service_duration_s' => a_kind_of(Numeric),
'pipeline_creation_caller' => 'source',
'pipeline_save_duration_s' => {
- 'avg' => 60, 'sum' => 60, 'count' => 1, 'max' => 60, 'min' => 60
+ 'sum' => 60, 'count' => 1, 'max' => 60
},
'pipeline_creation_duration_s' => {
- 'avg' => 20, 'sum' => 40, 'count' => 2, 'max' => 30, 'min' => 10
+ 'sum' => 40, 'count' => 2, 'max' => 30
}
}
end
diff --git a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb
index 604feeea325..82d5d0f292b 100644
--- a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb
@@ -898,7 +898,7 @@ RSpec.describe Gitlab::GitalyClient::OperationService do
end
shared_examples '#user_commit_files failure' do
- it 'raises a PreReceiveError' do
+ it 'raises an IndexError' do
expect_any_instance_of(Gitaly::OperationService::Stub)
.to receive(:user_commit_files).with(kind_of(Enumerator), kind_of(Hash))
.and_raise(structured_error)
@@ -912,7 +912,7 @@ RSpec.describe Gitlab::GitalyClient::OperationService do
context 'with missing file' do
let(:status_code) { GRPC::Core::StatusCodes::NOT_FOUND }
- let(:expected_message) { "File not found: README.md" }
+ let(:expected_message) { "A file with this name doesn't exist" }
let(:expected_error) do
Gitaly::UserCommitFilesError.new(
index_update: Gitaly::IndexError.new(
@@ -926,7 +926,7 @@ RSpec.describe Gitlab::GitalyClient::OperationService do
context 'with existing directory' do
let(:status_code) { GRPC::Core::StatusCodes::ALREADY_EXISTS }
- let(:expected_message) { "Directory already exists: dir1" }
+ let(:expected_message) { "A directory with this name already exists" }
let(:expected_error) do
Gitaly::UserCommitFilesError.new(
index_update: Gitaly::IndexError.new(
@@ -940,7 +940,7 @@ RSpec.describe Gitlab::GitalyClient::OperationService do
context 'with existing file' do
let(:status_code) { GRPC::Core::StatusCodes::ALREADY_EXISTS }
- let(:expected_message) { "File already exists: README.md" }
+ let(:expected_message) { "A file with this name already exists" }
let(:expected_error) do
Gitaly::UserCommitFilesError.new(
index_update: Gitaly::IndexError.new(
@@ -954,7 +954,7 @@ RSpec.describe Gitlab::GitalyClient::OperationService do
context 'with invalid path' do
let(:status_code) { GRPC::Core::StatusCodes::INVALID_ARGUMENT }
- let(:expected_message) { "Invalid path: invalid://file/name" }
+ let(:expected_message) { "invalid path: 'invalid://file/name'" }
let(:expected_error) do
Gitaly::UserCommitFilesError.new(
index_update: Gitaly::IndexError.new(
@@ -968,7 +968,7 @@ RSpec.describe Gitlab::GitalyClient::OperationService do
context 'with directory traversal' do
let(:status_code) { GRPC::Core::StatusCodes::INVALID_ARGUMENT }
- let(:expected_message) { "Directory traversal in path escapes repository: ../../../../etc/shadow" }
+ let(:expected_message) { "Path cannot include directory traversal" }
let(:expected_error) do
Gitaly::UserCommitFilesError.new(
index_update: Gitaly::IndexError.new(
@@ -982,7 +982,7 @@ RSpec.describe Gitlab::GitalyClient::OperationService do
context 'with empty path' do
let(:status_code) { GRPC::Core::StatusCodes::INVALID_ARGUMENT }
- let(:expected_message) { "Received empty path" }
+ let(:expected_message) { "You must provide a file path" }
let(:expected_error) do
Gitaly::UserCommitFilesError.new(
index_update: Gitaly::IndexError.new(
@@ -1009,16 +1009,33 @@ RSpec.describe Gitlab::GitalyClient::OperationService do
end
context 'with an exception without the detailed error' do
- let(:permission_error) do
- GRPC::PermissionDenied.new
- end
-
- it 'raises PermissionDenied' do
+ before do
expect_any_instance_of(Gitaly::OperationService::Stub)
.to receive(:user_commit_files).with(kind_of(Enumerator), kind_of(Hash))
- .and_raise(permission_error)
+ .and_raise(raised_error)
+ end
- expect { subject }.to raise_error(GRPC::PermissionDenied)
+ context 'with an index error from libgit2' do
+ let(:raised_error) do
+ GRPC::Internal.new('invalid path: .git/foo')
+ end
+
+ it 'raises IndexError' do
+ expect { subject }.to raise_error do |error|
+ expect(error).to be_a(Gitlab::Git::Index::IndexError)
+ expect(error.message).to eq('invalid path: .git/foo')
+ end
+ end
+ end
+
+ context 'with a generic error' do
+ let(:raised_error) do
+ GRPC::PermissionDenied.new
+ end
+
+ it 'raises PermissionDenied' do
+ expect { subject }.to raise_error(GRPC::PermissionDenied)
+ end
end
end
end
diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb
index f1ecc8c8ab5..8ca42a6f007 100644
--- a/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb
+++ b/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb
@@ -196,6 +196,22 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::DatabaseMetric do
end
end
+ context 'with 7 days time frame' do
+ subject do
+ database_metric_class.tap do |metric_class|
+ metric_class.relation { Issue }
+ metric_class.operation :count
+ end.new(time_frame: '7d')
+ end
+
+ it 'calculates a correct result' do
+ create(:issue, created_at: 10.days.ago)
+ create(:issue, created_at: 5.days.ago)
+
+ expect(subject.value).to eq(1)
+ end
+ end
+
context 'with additional parameters passed via options' do
subject do
database_metric_class.tap do |metric_class|