merritt-manifest 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+ require 'ostruct'
3
+ require 'tempfile'
4
+
5
+ module Merritt
6
+ describe Manifest::Object do
7
+
8
+ describe 'sample' do
9
+
10
+ attr_reader :files
11
+ attr_reader :manifest
12
+
13
+ before(:each) do
14
+ @files = [
15
+ {
16
+ file_url: 'http://merritt.cdlib.org/samples/4blocks.jpg',
17
+ hash_algorithm: 'md5',
18
+ hash_value: '0b21c6d48e815dd537d42dc1cfac0111',
19
+ file_name: '4blocks.jpg'
20
+ },
21
+ {
22
+ file_url: 'http://merritt.cdlib.org/samples/4blocks.txt',
23
+ hash_algorithm: 'md5',
24
+ hash_value: 'ed04a855f89f31f8dc8e9bb946f5f159',
25
+ file_name: '4blocks.txt'
26
+ }
27
+ ].map { |h| OpenStruct.new(h) }
28
+ @manifest = Manifest::Object.new(files: files)
29
+ end
30
+
31
+ describe :write_to_string do
32
+ it 'writes an object manifest' do
33
+ path = '4blocks.checkm'
34
+ expected = File.read("spec/data/#{path}")
35
+ actual = manifest.write_to_string
36
+ if actual != expected
37
+ now = Time.now.to_i
38
+ FileUtils.mkdir('tmp') unless File.directory?('tmp')
39
+ File.open("tmp/#{now}-expected-#{path}", 'w') { |f| f.write(expected) }
40
+ File.open("tmp/#{now}-actual-#{path}", 'w') { |f| f.write(actual) }
41
+ end
42
+ expect(actual).to eq(expected)
43
+ end
44
+ end
45
+
46
+ describe :write_to_file do
47
+ it 'writes to a file' do
48
+ file = Tempfile.new('manifest.checkm')
49
+ begin
50
+ manifest.write_to(file)
51
+ file.close
52
+ actual = IO.read(file.path)
53
+ path = '4blocks.checkm'
54
+ expected = File.read("spec/data/#{path}")
55
+ actual = manifest.write_to_string
56
+ if actual != expected
57
+ now = Time.now.to_i
58
+ FileUtils.mkdir('tmp') unless File.directory?('tmp')
59
+ File.open("tmp/#{now}-expected-#{path}", 'w') { |f| f.write(expected) }
60
+ File.open("tmp/#{now}-actual-#{path}", 'w') { |f| f.write(actual) }
61
+ end
62
+ ensure
63
+ file.delete
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,134 @@
1
+ require 'spec_helper'
2
+
3
+ module Merritt
4
+ describe Manifest do
5
+
6
+ attr_reader :dataone_profile
7
+
8
+ before(:each) do
9
+ @dataone_profile = 'http://uc3.cdlib.org/registry/ingest/manifest/mrt-dataone-manifest'
10
+ end
11
+
12
+ describe :new do
13
+ it 'creates a new manifest' do
14
+ manifest = Manifest.new(profile: dataone_profile)
15
+ expect(manifest).to be_a(Manifest)
16
+ end
17
+
18
+ describe :conformance do
19
+ it 'defaults to CheckM 0.7' do
20
+ manifest = Manifest.new(profile: dataone_profile)
21
+ expect(manifest.conformance).to eq('checkm_0.7')
22
+ end
23
+ end
24
+
25
+ describe :profile do
26
+ it 'accepts a string' do
27
+ profile_str = dataone_profile
28
+ manifest = Manifest.new(profile: profile_str)
29
+ expect(manifest.profile).to eq(URI.parse(profile_str))
30
+ end
31
+
32
+ it 'accepts a URI' do
33
+ profile = URI.parse(dataone_profile)
34
+ manifest = Manifest.new(profile: profile)
35
+ expect(manifest.profile).to eq(profile)
36
+ end
37
+
38
+ it 'requires a profile' do
39
+ expect { Manifest.new }.to raise_error(ArgumentError)
40
+ end
41
+
42
+ it 'requires profile to be a URL' do
43
+ expect { Manifest.new(profile: 'elvis') }.to raise_error(ArgumentError)
44
+ end
45
+
46
+ it 'requires a Merritt manifest profile' do
47
+ profile = 'http://example.org/my-profile'
48
+ expect { Manifest.new(profile: profile) }.to raise_error(ArgumentError)
49
+ end
50
+ end
51
+
52
+ describe :prefixes do
53
+ it 'defaults to empty' do
54
+ manifest = Manifest.new(profile: dataone_profile)
55
+ prefixes = manifest.prefixes
56
+ expect(prefixes).to be_a(Hash)
57
+ expect(prefixes).to be_empty
58
+ end
59
+
60
+ it 'normalizes keys to symbols and values to URIs' do
61
+ in_prefixes = {
62
+ :mrt => URI('http://merritt.cdlib.org/terms#'),
63
+ 'dom' => 'http://uc3.cdlib.org/ontology/dataonem',
64
+ :nfo => 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#'
65
+ }
66
+ manifest = Manifest.new(profile: dataone_profile, prefixes: in_prefixes)
67
+ out_prefixes = manifest.prefixes
68
+ expect(out_prefixes.size).to eq(in_prefixes.size)
69
+ expect(out_prefixes[:mrt]).to eq(in_prefixes[:mrt])
70
+ expect(out_prefixes[:dom]).to eq(URI(in_prefixes['dom']))
71
+ expect(out_prefixes[:nfo]).to eq(URI(in_prefixes[:nfo]))
72
+ end
73
+ end
74
+
75
+ describe :fields do
76
+ it 'defaults to empty' do
77
+ manifest = Manifest.new(profile: dataone_profile)
78
+ fields = manifest.fields
79
+ expect(fields).to be_an(Array)
80
+ expect(fields).to be_empty
81
+ end
82
+
83
+ it 'accepts a list of fields' do
84
+ in_fields = %w[dom:scienceMetadataFile dom:scienceMetadataFormat dom:scienceDataFile mrt:mimeType]
85
+ manifest = Manifest.new(
86
+ profile: dataone_profile,
87
+ fields: in_fields,
88
+ prefixes: {
89
+ mrt: 'http://merritt.cdlib.org/terms#',
90
+ dom: 'http://uc3.cdlib.org/ontology/dataonem'
91
+ }
92
+ )
93
+ out_fields = manifest.fields
94
+ expect(out_fields.size).to eq(in_fields.size)
95
+ expect(out_fields).to eq(in_fields)
96
+ expect(out_fields).not_to be(in_fields)
97
+ end
98
+ end
99
+
100
+ describe :entries do
101
+ it 'accepts a list of entries' do
102
+
103
+ in_entries = [
104
+ {
105
+ 'dom:scienceMetadataFile' => 'mrt-datacite.xml',
106
+ 'dom:scienceMetadataFormat' => 'http://datacite.org/schema/kernel-3.1',
107
+ 'dom:scienceDataFile' => 'Laney_300394_Exempt_Determination_Letter.pdf',
108
+ 'mrt:mimeType' => 'application/pdf'
109
+ },
110
+ {
111
+ 'dom:scienceMetadataFile' => 'mrt-oaidc.xml',
112
+ 'dom:scienceMetadataFormat' => 'http://dublincore.org/schemas/xmls/qdc/2008/02/11/qualifieddc.xsd',
113
+ 'dom:scienceDataFile' => 'Laney_300394_Exempt_Determination_Letter.pdf',
114
+ 'mrt:mimeType' => 'application/pdf'
115
+ }
116
+ ]
117
+
118
+ manifest = Manifest.new(
119
+ profile: dataone_profile,
120
+ fields: %w[dom:scienceMetadataFile dom:scienceMetadataFormat dom:scienceDataFile mrt:mimeType],
121
+ prefixes: {
122
+ mrt: 'http://merritt.cdlib.org/terms#',
123
+ dom: 'http://uc3.cdlib.org/ontology/dataonem'
124
+ },
125
+ entries: in_entries
126
+ )
127
+
128
+ out_entries = manifest.entries
129
+ expect(out_entries).to eq(in_entries)
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merritt-manifest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Moles
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typesafe_enum
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.14'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.14'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov-console
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.47'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.47'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ description: Merritt manifest generation library
126
+ email:
127
+ - david.moles@ucop.edu
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".idea/emacs.xml"
134
+ - ".idea/encodings.xml"
135
+ - ".idea/inspectionProfiles/Project_Default.xml"
136
+ - ".idea/misc.xml"
137
+ - ".idea/modules.xml"
138
+ - ".idea/sbt.xml"
139
+ - ".rubocop.yml"
140
+ - ".ruby-version"
141
+ - ".travis.yml"
142
+ - ".yardopts"
143
+ - Gemfile
144
+ - LICENSE.md
145
+ - README.md
146
+ - Rakefile
147
+ - lib/merritt.rb
148
+ - lib/merritt/manifest.rb
149
+ - lib/merritt/manifest/data_one.rb
150
+ - lib/merritt/manifest/fields.rb
151
+ - lib/merritt/manifest/file.rb
152
+ - lib/merritt/manifest/module_info.rb
153
+ - lib/merritt/manifest/object.rb
154
+ - lib/merritt/util.rb
155
+ - merritt-manifest.gemspec
156
+ - merritt-manifest.iml
157
+ - spec/.rubocop.yml
158
+ - spec/data/4blocks.checkm
159
+ - spec/data/mrt-dataone-manifest.txt
160
+ - spec/data/sampleBatchOfContainers.checkm
161
+ - spec/data/sampleBatchOfFiles.checkm
162
+ - spec/data/sampleBatchOfManifests.checkm
163
+ - spec/spec_helper.rb
164
+ - spec/unit/merritt/manifest/data_one_spec.rb
165
+ - spec/unit/merritt/manifest/fields_spec.rb
166
+ - spec/unit/merritt/manifest/object_spec.rb
167
+ - spec/unit/merritt/manifest_spec.rb
168
+ homepage: http://github.com/merritt-manifest
169
+ licenses:
170
+ - MIT
171
+ metadata: {}
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubyforge_project:
188
+ rubygems_version: 2.6.8
189
+ signing_key:
190
+ specification_version: 4
191
+ summary: Merritt manifest generation library
192
+ test_files:
193
+ - spec/.rubocop.yml
194
+ - spec/data/4blocks.checkm
195
+ - spec/data/mrt-dataone-manifest.txt
196
+ - spec/data/sampleBatchOfContainers.checkm
197
+ - spec/data/sampleBatchOfFiles.checkm
198
+ - spec/data/sampleBatchOfManifests.checkm
199
+ - spec/spec_helper.rb
200
+ - spec/unit/merritt/manifest/data_one_spec.rb
201
+ - spec/unit/merritt/manifest/fields_spec.rb
202
+ - spec/unit/merritt/manifest/object_spec.rb
203
+ - spec/unit/merritt/manifest_spec.rb