-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV-1086: summarize deletion reports
- dedupes output - omits anything that is in the target dataset at time of report
- Loading branch information
Showing
9 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Datasets | ||
class DedupeDeleteLog | ||
attr_reader :profile | ||
attr_reader :files | ||
|
||
def initialize(profile:, files:) | ||
@profile = profile | ||
@files = files | ||
@path_resolver = Datasets.config.dest_path_resolver[profile] | ||
end | ||
|
||
def compile_results | ||
Tempfile.create("dedupe-deletes") do |f| | ||
filename = f.path | ||
f.close | ||
system("sort #{files.join(" ")} | uniq > #{filename}") | ||
f = File.open(filename) | ||
yield f.map(&:strip).select { |id| not_in_dataset(id) } | ||
end | ||
end | ||
|
||
def not_in_dataset(id) | ||
(namespace, id) = id.split(".", 2) | ||
volume = Volume.new(namespace: namespace, id: id, access_profile: :none, right: :none) | ||
!File.exist?(path_resolver.path(volume)) | ||
end | ||
|
||
private | ||
|
||
attr_reader :path_resolver | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require_relative "spec_helper" | ||
require "dedupe_delete_log" | ||
|
||
module Datasets | ||
RSpec.describe DedupeDeleteLog do | ||
# needs the dataset paths there | ||
include_context "integration" do | ||
let(:profile) { :pd } | ||
|
||
it "takes a profile and an array of files as input" do | ||
expect(DedupeDeleteLog.new(profile: profile, files: ["foo", "bar"])).not_to be_nil | ||
end | ||
|
||
it "outputs each item at most once" do | ||
files = Array.new(2) { Tempfile.create("dedupe-deletes") } | ||
begin | ||
files[0].puts("test.id1", "test.id2") | ||
files[1].puts("test.id3", "test.id2") | ||
files.map(&:close) | ||
|
||
DedupeDeleteLog.new(profile: profile, files: files.map(&:path)).compile_results do |results| | ||
expect(results).to contain_exactly("test.id1", "test.id2", "test.id3") | ||
end | ||
ensure | ||
files.map { |f| File.unlink(f) } | ||
end | ||
end | ||
|
||
it "only outputs deletes that aren't present in the current dataset" do | ||
Tempfile.create("dedupe-deletes") do |f| | ||
f.puts("test.still_there", "test.not_there") | ||
f.close | ||
|
||
volume = Volume.new(namespace: "test", id: "still_there", access_profile: :open, right: :pd) | ||
writer = Datasets.config.volume_writer[profile] | ||
src_path_resolver = Datasets.config.src_path_resolver[profile] | ||
src_path = src_path_resolver.path(volume) | ||
src_path.parent.mkpath | ||
FileUtils.touch(src_path) | ||
writer.save(volume, src_path) | ||
|
||
DedupeDeleteLog.new(profile: profile, files: [f.path]).compile_results do |results| | ||
expect(results).to contain_exactly("test.not_there") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters