bagit 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +22 -0
- data/.travis.yml +1 -2
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/Rakefile +8 -2
- data/bagit.gemspec +4 -3
- data/bin/bagit +30 -33
- data/lib/bagit.rb +1 -1
- data/lib/bagit/bag.rb +20 -27
- data/lib/bagit/fetch.rb +14 -20
- data/lib/bagit/file.rb +10 -15
- data/lib/bagit/info.rb +43 -57
- data/lib/bagit/manifest.rb +43 -48
- data/lib/bagit/string.rb +2 -4
- data/lib/bagit/valid.rb +67 -75
- data/lib/bagit/version.rb +1 -1
- data/spec/bagit_spec.rb +34 -30
- data/spec/fetch_spec.rb +29 -35
- data/spec/manifest_spec.rb +99 -108
- data/spec/spec_helper.rb +3 -5
- data/spec/tag_info_spec.rb +91 -99
- data/spec/tag_spec.rb +47 -50
- data/spec/util/bagit_matchers.rb +3 -14
- data/spec/validation_spec.rb +107 -110
- metadata +35 -20
data/spec/tag_spec.rb
CHANGED
@@ -1,62 +1,59 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@bag.add_tag_file("tag-#{n}") { |io| io.write rio.read(16)}
|
4
|
+
describe BagIt::Bag do
|
5
|
+
describe "Tag Specs" do
|
6
|
+
before do
|
7
|
+
@sandbox = Sandbox.new
|
8
|
+
|
9
|
+
# make the bag
|
10
|
+
@bag_path = File.join @sandbox.to_s, 'the_bag'
|
11
|
+
@bag = described_class.new(@bag_path)
|
12
|
+
|
13
|
+
# add some files
|
14
|
+
File.open('/dev/urandom') do |rio|
|
15
|
+
10.times do |n|
|
16
|
+
@bag.add_file("file-#{n}-💩
|
17
|
+
@bag.add_tag_file("tag-#{n}") { |io| io.write rio.read(16) }
|
18
|
+
end
|
20
19
|
end
|
21
|
-
|
22
20
|
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
after(:each) do
|
27
|
-
@sandbox.cleanup!
|
28
|
-
end
|
29
|
-
describe "#add_tag_file" do
|
30
|
-
it "should allow addition of tag files via io" do
|
31
|
-
@bag.add_tag_file("foo") { |io| io.puts 'all alone' }
|
32
|
-
expect(File.join(@bag_path, "foo")).to exist_on_fs
|
33
|
-
end
|
34
|
-
it "should allow addition of bag files within directories using io" do
|
35
|
-
@bag.add_tag_file("fedora/foo") { |io| io.puts 'all alone' }
|
36
|
-
expect(File.join(@bag_path, "fedora","foo")).to exist_on_fs
|
37
|
-
end
|
38
|
-
it "should allow addition of deep tag files" do
|
39
|
-
@bag.add_tag_file("fedora/foo/newfoo/deep") {|io| io.puts "woah that's deep"}
|
40
|
-
expect(File.join(@bag_path,"fedora","foo","newfoo","deep")).to exist_on_fs
|
22
|
+
after do
|
23
|
+
@sandbox.cleanup!
|
41
24
|
end
|
42
|
-
|
43
|
-
|
25
|
+
describe "#add_tag_file" do
|
26
|
+
it "allows addition of tag files via io" do
|
27
|
+
@bag.add_tag_file("foo") { |io| io.puts 'all alone' }
|
28
|
+
expect(File.join(@bag_path, "foo")).to exist_on_fs
|
29
|
+
end
|
30
|
+
it "allows addition of bag files within directories using io" do
|
31
|
+
@bag.add_tag_file("fedora/foo") { |io| io.puts 'all alone' }
|
32
|
+
expect(File.join(@bag_path, "fedora", "foo")).to exist_on_fs
|
33
|
+
end
|
34
|
+
it "allows addition of deep tag files" do
|
35
|
+
@bag.add_tag_file("fedora/foo/newfoo/deep") { |io| io.puts "woah that's deep" }
|
36
|
+
expect(File.join(@bag_path, "fedora", "foo", "newfoo", "deep")).to exist_on_fs
|
37
|
+
end
|
38
|
+
it "does not allow overwriting of tag files" do
|
39
|
+
expect { @bag.add_tag_file("tag-0") { |io| io.puts 'overwrite!' } }.to raise_error(RuntimeError)
|
40
|
+
end
|
41
|
+
it "allows addition of tag files via copy" do
|
42
|
+
src_path = File.join @sandbox.to_s, 'somefile'
|
43
|
+
File.open(src_path, 'w') { |io| io.puts "something" }
|
44
|
+
@bag.add_tag_file("foo", src_path) { |io| io.puts 'all alone' }
|
45
|
+
expect(File.join(@bag_path, "foo")).to exist_on_fs
|
46
|
+
end
|
44
47
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
expect(File.join(@bag_path, "foo")).to exist_on_fs
|
48
|
+
describe "#remove_tag_file" do
|
49
|
+
it "raises an error when removing non existant files" do
|
50
|
+
expect { @bag.remove_tag_file("file-x") }.to raise_error(RuntimeError)
|
51
|
+
end
|
50
52
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
describe "#delete_tag_file" do
|
54
|
+
it "raises an error when deleting non existant tag files" do
|
55
|
+
expect { @bag.delete_tag_file("file-x") }.to raise_error(RuntimeError)
|
56
|
+
end
|
55
57
|
end
|
56
58
|
end
|
57
|
-
describe "#delete_tag_file" do
|
58
|
-
it "should raise an error when deleting non existant tag files" do
|
59
|
-
expect { @bag.delete_tag_file("file-x") }.to raise_error(RuntimeError)
|
60
|
-
end
|
61
|
-
end
|
62
59
|
end
|
data/spec/util/bagit_matchers.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
module BagitMatchers
|
2
|
-
|
3
|
-
class BeIn
|
4
|
-
|
5
|
-
|
2
|
+
class BeIn
|
6
3
|
def initialize(*expected_collection)
|
7
4
|
@expected = expected_collection
|
8
5
|
end
|
@@ -20,16 +17,13 @@ module BagitMatchers
|
|
20
17
|
"expected <#{@target}> to not be in collection <#{@expected}>"
|
21
18
|
end
|
22
19
|
alias negative_failure_message failure_message_when_negated
|
23
|
-
|
24
20
|
end
|
25
21
|
|
26
22
|
def be_in(*expected_collection)
|
27
23
|
BeIn.new(*expected_collection)
|
28
24
|
end
|
29
25
|
|
30
|
-
class ExistOnFS
|
31
|
-
|
32
|
-
|
26
|
+
class ExistOnFS
|
33
27
|
def matches?(target)
|
34
28
|
@target = target
|
35
29
|
File.exist? target
|
@@ -43,14 +37,9 @@ module BagitMatchers
|
|
43
37
|
"expected <#{@target}> to not exist but it does"
|
44
38
|
end
|
45
39
|
alias negative_failure_message failure_message_when_negated
|
46
|
-
|
47
40
|
end
|
48
41
|
|
49
|
-
def exist_on_fs
|
42
|
+
def exist_on_fs
|
50
43
|
ExistOnFS.new
|
51
44
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
45
|
end
|
data/spec/validation_spec.rb
CHANGED
@@ -1,144 +1,141 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
10.times do |n|
|
18
|
-
@bag.add_file("file-#{n}-💩
|
4
|
+
describe BagIt::Bag do
|
5
|
+
describe "a valid bag" do
|
6
|
+
before do
|
7
|
+
@sandbox = Sandbox.new
|
8
|
+
|
9
|
+
# make the bag
|
10
|
+
@bag_path = File.join @sandbox.to_s, 'the_bag'
|
11
|
+
@bag = described_class.new @bag_path
|
12
|
+
|
13
|
+
# add some files
|
14
|
+
File.open('/dev/urandom') do |rio|
|
15
|
+
10.times do |n|
|
16
|
+
@bag.add_file("file-#{n}-💩
|
19
17
|
") { |io| io.write rio.read(16) }
|
20
|
-
|
18
|
+
@bag.add_tag_file("tag-#{n}") { |io| io.write rio.read(16) }
|
19
|
+
end
|
21
20
|
end
|
22
21
|
|
22
|
+
@bag.manifest!
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
after do
|
26
|
+
@sandbox.cleanup!
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
it "validates with no errors" do
|
30
|
+
expect(@bag).to be_valid
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
it "is invalid if there is a file that's in the bag, but not in the manifest" do
|
34
|
+
# add a file into the bag through the back door
|
35
|
+
File.open(File.join(@bag.data_dir, 'not-manifested'), 'w') do |io|
|
36
|
+
io.puts 'nothing to see here, move along'
|
37
|
+
end
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
io.puts 'nothing to see here, move along'
|
39
|
+
@bag.validate_only('true_for/completeness')
|
40
|
+
expect(@bag.errors.on(:completeness)).not_to be_empty
|
41
|
+
expect(@bag).not_to be_valid
|
40
42
|
end
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
it "should be invalid if there are files that are in the manifest but not in the bag" do
|
48
|
-
# add a file and then remove it through the back door
|
49
|
-
@bag.add_file("file-k") { |io| io.puts 'time to go' }
|
50
|
-
@bag.manifest!
|
44
|
+
it "is invalid if there are files that are in the manifest but not in the bag" do
|
45
|
+
# add a file and then remove it through the back door
|
46
|
+
@bag.add_file("file-k") { |io| io.puts 'time to go' }
|
47
|
+
@bag.manifest!
|
51
48
|
|
52
|
-
|
49
|
+
FileUtils.rm File.join(@bag.bag_dir, 'data', 'file-k')
|
53
50
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
@bag.validate_only('true_for/completeness')
|
52
|
+
expect(@bag.errors.on(:completeness)).not_to be_empty
|
53
|
+
expect(@bag).not_to be_valid
|
54
|
+
end
|
58
55
|
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
it "is invalid if there is a fixity problem" do
|
57
|
+
# tweak a file through the back door
|
58
|
+
File.open(@bag.bag_files[0], 'a') { |io| io.puts 'oops!' }
|
62
59
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
@bag.validate_only('true_for/consistency')
|
61
|
+
expect(@bag.errors.on(:consistency)).not_to be_empty
|
62
|
+
expect(@bag).not_to be_valid
|
63
|
+
end
|
67
64
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
65
|
+
it "calculates sha1 correctly for a big file" do
|
66
|
+
@bag.add_file 'big-data-file' do |fh|
|
67
|
+
count = 0
|
68
|
+
while count < 1024 * 512
|
69
|
+
fh.write "1" * 1024
|
70
|
+
count += 1
|
71
|
+
end
|
74
72
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
File.open(sha1_manifest).each_line do |line|
|
73
|
+
@bag.manifest!
|
74
|
+
sha1_manifest = File.join @bag_path, 'manifest-sha1.txt'
|
75
|
+
checksums = {}
|
76
|
+
File.open(sha1_manifest).each_line do |line|
|
80
77
|
fixity, path = line.split(' ')
|
81
78
|
checksums[path] = fixity
|
79
|
+
end
|
80
|
+
expected = checksums['data/big-data-file']
|
81
|
+
expect(expected).to eq('12be64c30968bb90136ee695dc58f4b2276968c6')
|
82
82
|
end
|
83
|
-
expected = checksums['data/big-data-file']
|
84
|
-
expect(expected).to eq('12be64c30968bb90136ee695dc58f4b2276968c6')
|
85
|
-
end
|
86
83
|
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
it "validates by oxum when needed" do
|
85
|
+
expect(@bag.valid_oxum?).to eq(true)
|
86
|
+
end
|
90
87
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
it "should validate false by oxum when file count is incorrect" do
|
100
|
-
# tweak oxum through backdoor
|
101
|
-
File.open(@bag.bag_info_txt_file, 'a') { |f| f.write "Payload-Oxum: " + @bag.bag_info["Payload-Oxum"].split('.')[0] + '.0' }
|
102
|
-
expect(@bag.valid_oxum?).to eq(false)
|
103
|
-
end
|
88
|
+
it "raises a sensible error when the manifest algorithm is unknown" do
|
89
|
+
# add a manifest with an unsupported algorithm
|
90
|
+
File.open(File.join(@bag.bag_dir, 'manifest-sha999.txt'), 'w') do |io|
|
91
|
+
io.puts "digest-does-not-matter data/file-0\n"
|
92
|
+
end
|
93
|
+
expect { @bag.valid? }.to raise_error ArgumentError
|
94
|
+
end
|
104
95
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
96
|
+
it "validates false by oxum when file count is incorrect" do
|
97
|
+
# tweak oxum through backdoor
|
98
|
+
File.open(@bag.bag_info_txt_file, 'a') { |f| f.write "Payload-Oxum: " + @bag.bag_info["Payload-Oxum"].split('.')[0] + '.0' }
|
99
|
+
expect(@bag.valid_oxum?).to eq(false)
|
100
|
+
end
|
110
101
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
@bag.
|
115
|
-
|
116
|
-
end
|
117
|
-
@bag.tag_files.each do |tag_file|
|
118
|
-
FileUtils::rm tag_file
|
119
|
-
end
|
120
|
-
@bag.tagmanifest_files.each do |tagmanifest_file|
|
121
|
-
FileUtils::rm tagmanifest_file
|
122
|
-
end
|
102
|
+
it "validates false by oxum when octetstream size is incorrect" do
|
103
|
+
# tweak oxum through backdoor
|
104
|
+
File.open(@bag.bag_info_txt_file, 'a') { |f| f.write "Payload-Oxum: 1." + @bag.bag_info["Payload-Oxum"].split('.')[1] }
|
105
|
+
expect(@bag.valid_oxum?).to eq(false)
|
106
|
+
end
|
123
107
|
|
124
|
-
|
125
|
-
|
126
|
-
|
108
|
+
describe "tag manifest validation" do
|
109
|
+
it "is invalid if there are no manifest files at all even when there are no files" do
|
110
|
+
# remove all files, tag/manifest files & tagmanifest files through the back door
|
111
|
+
@bag.bag_files.each do |bag_file|
|
112
|
+
FileUtils.rm bag_file
|
113
|
+
end
|
114
|
+
@bag.tag_files.each do |tag_file|
|
115
|
+
FileUtils.rm tag_file
|
116
|
+
end
|
117
|
+
@bag.tagmanifest_files.each do |tagmanifest_file|
|
118
|
+
FileUtils.rm tagmanifest_file
|
119
|
+
end
|
120
|
+
|
121
|
+
# @bag.should_not be_valid
|
122
|
+
expect(@bag).not_to be_valid
|
123
|
+
expect(@bag.errors.on(:completeness)).not_to be_empty
|
124
|
+
end
|
127
125
|
end
|
128
|
-
end
|
129
126
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
127
|
+
describe "tag manifest validation" do
|
128
|
+
it "is invalid if listed tag file does not exist" do
|
129
|
+
# add a file and then remove it through the back door
|
130
|
+
@bag.add_tag_file("tag-k") { |io| io.puts 'time to go' }
|
131
|
+
@bag.tagmanifest!
|
135
132
|
|
136
|
-
|
133
|
+
FileUtils.rm File.join(@bag.bag_dir, 'tag-k')
|
137
134
|
|
138
|
-
|
139
|
-
|
140
|
-
|
135
|
+
# @bag.should_not be_valid
|
136
|
+
expect(@bag).not_to be_valid
|
137
|
+
expect(@bag.errors.on(:completeness)).not_to be_empty
|
138
|
+
end
|
141
139
|
end
|
142
140
|
end
|
143
|
-
|
144
141
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bagit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Johnson, Francesco Lazzarino, Jamie Little
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: validatable
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: bixby
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,35 +53,35 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: coveralls
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: pry
|
98
|
+
name: pry-byebug
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,19 +109,33 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rake
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '10.4'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '10.4'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3'
|
125
139
|
description: Ruby Library and Command Line tools for bagit
|
126
140
|
email: jamie@jamielittle.org
|
127
141
|
executables:
|
@@ -130,6 +144,7 @@ extensions: []
|
|
130
144
|
extra_rdoc_files: []
|
131
145
|
files:
|
132
146
|
- ".gitignore"
|
147
|
+
- ".rubocop.yml"
|
133
148
|
- ".travis.yml"
|
134
149
|
- Gemfile
|
135
150
|
- LICENSE.txt
|