Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jayamala17 committed May 17, 2024
1 parent 5ec2561 commit c425821
Showing 1 changed file with 23 additions and 76 deletions.
99 changes: 23 additions & 76 deletions test/test_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ def setup
)
end

def create_test_data
bag_identifier_one = "repository.context-0001"
bag_identifier_two = "repository.context-0002"
deposited_at = Time.utc(2024, 3, 18)

@status_event_repo.create(
bag_identifier: bag_identifier_one,
status: BagStatus::DEPOSITED,
timestamp: deposited_at
)

@status_event_repo.create(
bag_identifier: bag_identifier_two,
status: BagStatus::FAILED,
timestamp: deposited_at
)
end

def test_set_last_successful_run
expected_time = (@start_time.to_i * 1000)
@registry_mock.expect(
Expand Down Expand Up @@ -56,22 +74,7 @@ def test_set_processing_duration
end

def test_set_success_count
@bag_identifier_one = "repository.context-0001"
@bag_identifier_two = "repository.context-0002"
@deposited_at = Time.utc(2024, 3, 18)

@status_event_repo.create(
bag_identifier: @bag_identifier_one,
status: BagStatus::DEPOSITED,
timestamp: @deposited_at
)

@status_event_repo.create(
bag_identifier: @bag_identifier_two,
status: BagStatus::FAILED,
timestamp: @deposited_at
)

create_test_data
@registry_mock.expect(
:gauge,
@gauge_mock,
Expand All @@ -87,21 +90,7 @@ def test_set_success_count
end

def test_set_failed_count
@bag_identifier_one = "repository.context-0001"
@bag_identifier_two = "repository.context-0002"
@deposited_at = Time.utc(2024, 3, 18)

@status_event_repo.create(
bag_identifier: @bag_identifier_one,
status: BagStatus::DEPOSITED,
timestamp: @deposited_at
)

@status_event_repo.create(
bag_identifier: @bag_identifier_two,
status: BagStatus::FAILED,
timestamp: @deposited_at
)
create_test_data
expected = 1
@registry_mock.expect(
:gauge,
Expand All @@ -117,62 +106,20 @@ def test_set_failed_count
end

def test_get_latest_bag_events_by_time
@bag_identifier_one = "repository.context-0001"
@bag_identifier_two = "repository.context-0002"
@deposited_at = Time.utc(2024, 3, 18)

@status_event_repo.create(
bag_identifier: @bag_identifier_one,
status: BagStatus::DEPOSITED,
timestamp: @deposited_at
)

@status_event_repo.create(
bag_identifier: @bag_identifier_two,
status: BagStatus::FAILED,
timestamp: @deposited_at
)
create_test_data
actual_result = @metrics.get_latest_bag_events_by_time
assert_equal 2, actual_result.length
end

def test_get_success_count
@bag_identifier_one = "repository.context-0001"
@bag_identifier_two = "repository.context-0002"
@deposited_at = Time.utc(2024, 3, 18)

@status_event_repo.create(
bag_identifier: @bag_identifier_one,
status: BagStatus::DEPOSITED,
timestamp: @deposited_at
)

@status_event_repo.create(
bag_identifier: @bag_identifier_two,
status: BagStatus::FAILED,
timestamp: @deposited_at
)
create_test_data
events_by_time = @metrics.get_latest_bag_events_by_time
actual_result = @metrics.get_success_count(events_by_time)
assert_equal 1, actual_result
end

def test_get_failure_count
@bag_identifier_one = "repository.context-0001"
@bag_identifier_two = "repository.context-0002"
@deposited_at = Time.utc(2024, 3, 18)

@status_event_repo.create(
bag_identifier: @bag_identifier_one,
status: BagStatus::DEPOSITED,
timestamp: @deposited_at
)

@status_event_repo.create(
bag_identifier: @bag_identifier_two,
status: BagStatus::FAILED,
timestamp: @deposited_at
)
create_test_data
events_by_time = @metrics.get_latest_bag_events_by_time
actual_result = @metrics.get_failure_count(events_by_time)
assert_equal 1, actual_result
Expand Down

0 comments on commit c425821

Please sign in to comment.