Skip to content

Commit

Permalink
feat: restructure logs from DeleteOverwrittenData to match CleanIncre…
Browse files Browse the repository at this point in the history
…mental
  • Loading branch information
bethesque committed Feb 22, 2023
1 parent 53b171b commit f11a941
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
10 changes: 8 additions & 2 deletions lib/pact_broker/db/delete_overwritten_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ def call
kept_counts[:pact_versions] = db[:pact_versions].count
kept_counts[:triggered_webhooks] = db[:triggered_webhooks].count

# TODO swap the hierarchy around so it matches the clean task

if dry_run?
to_keep = deleted_counts.keys.each_with_object({}) do | table_name, new_counts |
new_counts[table_name] = kept_counts[table_name] - deleted_counts[table_name]
end
{ toDelete: deleted_counts, toKeep: to_keep }
deleted_counts.each_with_object({}) do | (key, value), new_hash |
new_hash[key] = { toDelete: value, toKeep: to_keep[key] }
end
else
{ deleted: deleted_counts, kept: kept_counts }
deleted_counts.each_with_object({}) do | (key, value), new_hash |
new_hash[key] = { deleted: value, kept: kept_counts[key] }
end
end
end

Expand Down
22 changes: 16 additions & 6 deletions spec/lib/pact_broker/db/delete_overwritten_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ module DB
end

it "returns a report" do
expect(subject[:deleted][:pact_publications]).to eq 1
expect(subject[:kept][:pact_publications]).to eq 1
expect(subject[:pact_publications]).to eq(deleted: 1, kept: 1)
end

context "when dry_run is true" do
Expand All @@ -35,6 +34,10 @@ module DB
it "does not delete anything" do
expect { subject }.to_not change{ db[:pact_publications].count }
end

it "returns a report" do
expect(subject[:pact_publications]).to eq(toDelete: 1, toKeep: 1)
end
end
end

Expand All @@ -56,8 +59,8 @@ module DB
end

it "returns a report" do
expect(subject[:deleted][:verification_results]).to eq 1
expect(subject[:kept][:verification_results]).to eq 1
expect(subject[:verification_results][:deleted]).to eq 1
expect(subject[:verification_results][:kept]).to eq 1
end
end

Expand All @@ -75,8 +78,7 @@ module DB
end

it "returns a report" do
expect(subject[:deleted][:pact_versions]).to eq 1
expect(subject[:kept][:pact_versions]).to eq 2
expect(subject[:pact_versions]).to eq(deleted: 1, kept: 2)
end

context "when dry_run is true" do
Expand Down Expand Up @@ -139,12 +141,20 @@ module DB
expect { subject }.to change { PactBroker::Webhooks::TriggeredWebhook.count }.by(-2)
end

it "returns a report" do
expect(subject[:triggered_webhooks]).to eq(deleted: 2, kept: 2)
end

context "when dry_run is true" do
let(:dry_run) { true }

it "does not delete anything" do
expect { subject }.to_not change{ PactBroker::Webhooks::TriggeredWebhook.count }
end

it "returns a report" do
expect(subject[:triggered_webhooks]).to eq(toDelete: 2, toKeep: 2)
end
end

context "when all the records are younger than the max age" do
Expand Down

0 comments on commit f11a941

Please sign in to comment.