2021-09-30 23:02:18 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Gitlab::GithubImport::ObjectCounter, :clean_gitlab_redis_cache do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
|
|
|
it 'validates the operation being incremented' do
|
|
|
|
expect { described_class.increment(project, :issue, :unknown) }
|
2021-10-27 15:23:28 +05:30
|
|
|
.to raise_error(ArgumentError, 'operation must be fetched or imported')
|
2021-09-30 23:02:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'increments the counter and saves the key to be listed in the summary later' do
|
|
|
|
expect(Gitlab::Metrics)
|
|
|
|
.to receive(:counter)
|
|
|
|
.twice
|
|
|
|
.with(:github_importer_fetched_issue, 'The number of fetched Github Issue')
|
|
|
|
.and_return(double(increment: true))
|
|
|
|
|
|
|
|
expect(Gitlab::Metrics)
|
|
|
|
.to receive(:counter)
|
|
|
|
.twice
|
|
|
|
.with(:github_importer_imported_issue, 'The number of imported Github Issue')
|
|
|
|
.and_return(double(increment: true))
|
|
|
|
|
|
|
|
described_class.increment(project, :issue, :fetched)
|
|
|
|
described_class.increment(project, :issue, :fetched)
|
|
|
|
described_class.increment(project, :issue, :imported)
|
|
|
|
described_class.increment(project, :issue, :imported)
|
|
|
|
|
|
|
|
expect(described_class.summary(project)).to eq({
|
|
|
|
'fetched' => { 'issue' => 2 },
|
|
|
|
'imported' => { 'issue' => 2 }
|
|
|
|
})
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
it 'does not increment the counter if the given value is <= 0' do
|
|
|
|
expect(Gitlab::Metrics)
|
|
|
|
.not_to receive(:counter)
|
|
|
|
|
|
|
|
expect(Gitlab::Metrics)
|
|
|
|
.not_to receive(:counter)
|
|
|
|
|
|
|
|
described_class.increment(project, :issue, :fetched, value: 0)
|
|
|
|
described_class.increment(project, :issue, :imported, value: nil)
|
|
|
|
|
|
|
|
expect(described_class.summary(project)).to eq({
|
|
|
|
'fetched' => {},
|
|
|
|
'imported' => {}
|
|
|
|
})
|
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
end
|