|
| 1 | +describe ChecksumFileGenerator do |
| 2 | + include_context "uses temp dir" |
| 3 | + context ".write" do |
| 4 | + it "writes an checksum.md5 file for files in a given directory" do |
| 5 | + FileUtils.cp("spec/fixtures/10_10_8_400.jp2", temp_dir_path) |
| 6 | + described_class.write(temp_dir_path) |
| 7 | + checksum_contents = File.read(File.join(temp_dir_path, "checksum.md5")) |
| 8 | + expect(checksum_contents).to include(" 10_10_8_400.jp2") |
| 9 | + end |
| 10 | + end |
| 11 | +end |
| 12 | + |
| 13 | +describe GenerateChecksums do |
| 14 | + include_context "uses temp dir" |
| 15 | + let(:barcode) { "39015002231713" } |
| 16 | + let(:shipment_path) { "#{temp_dir_path}/test_shipment" } |
| 17 | + let(:item_path) { "#{shipment_path}/#{barcode}" } |
| 18 | + let(:shipment) { Shipment.new(shipment_path) } |
| 19 | + subject do |
| 20 | + described_class.new(shipment, config: Config.new({no_progress: true})) |
| 21 | + end |
| 22 | + |
| 23 | + def set_up_shipment |
| 24 | + FileUtils.mkdir_p(item_path) |
| 25 | + FileUtils.cp("spec/fixtures/10_10_8_400.jp2", item_path) |
| 26 | + end |
| 27 | + |
| 28 | + it "creates a checksum file" do |
| 29 | + set_up_shipment |
| 30 | + |
| 31 | + subject.run! |
| 32 | + checksum_contents = File.read(File.join(item_path, "checksum.md5")) |
| 33 | + expect(checksum_contents).to include(" 10_10_8_400.jp2") |
| 34 | + end |
| 35 | + |
| 36 | + it "original checksum file is removed before calculating checksum" do |
| 37 | + set_up_shipment |
| 38 | + FileUtils.touch("#{item_path}/checksum.md5") |
| 39 | + subject.run! |
| 40 | + checksum_contents = File.read(File.join(item_path, "checksum.md5")) |
| 41 | + expect(checksum_contents).to include(" 10_10_8_400.jp2") |
| 42 | + expect(checksum_contents).not_to include(" checksum.md5") |
| 43 | + end |
| 44 | +end |
0 commit comments