summaryrefslogtreecommitdiff
path: root/spec/integration/core
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-01 11:38:33 -0600
committermo khan <mo.khan@gmail.com>2020-05-01 11:38:33 -0600
commit52b49b63f3c6390499131e11112c1d1c4dbaea04 (patch)
tree93ed4c430c23a4487c659446a2167b62b48f39b3 /spec/integration/core
parentbda97276f175dfa19e281c2d72411d21a8b0bc79 (diff)
Start to build internal index
Diffstat (limited to 'spec/integration/core')
-rw-r--r--spec/integration/core/cache_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/integration/core/cache_spec.rb b/spec/integration/core/cache_spec.rb
index ef4c477..6896134 100644
--- a/spec/integration/core/cache_spec.rb
+++ b/spec/integration/core/cache_spec.rb
@@ -26,4 +26,52 @@ RSpec.describe Spandx::Core::Cache do
include_examples 'each data file', 'rubygems', :rubygems
include_examples 'each data file', 'nuget', :cache
+
+ describe "#insert" do
+ subject { described_class.new('rubygems', root: root_dir) }
+
+ let(:root_dir) { Dir.mktmpdir }
+
+ after do
+ FileUtils.remove_entry(root_dir)
+ end
+
+ context "when inserting a new record" do
+ let(:dependency_name) { SecureRandom.uuid }
+ let(:version) { "#{rand(10)}.#{rand(10)}.#{rand(10)}" }
+
+ before do
+ subject.insert(dependency_name, version, ['MIT'])
+ end
+
+ specify { expect(subject.licenses_for(dependency_name, version)).to match_array(['MIT']) }
+ end
+ end
+
+ describe "#rebuild_index" do
+ subject { described_class.new('rubygems', root: root_dir) }
+
+ let(:root_dir) { Dir.mktmpdir }
+
+ after do
+ FileUtils.remove_entry(root_dir)
+ end
+
+ context "When new items are added to the catalogue" do
+ before do
+ subject.insert('spandx', '0.0.0', ['MIT'])
+ subject.insert('bolt', '0.2.0', ['Apache-2.0'])
+ subject.insert('spandx', '0.1.0', ['MIT'])
+
+ subject.rebuild_index
+ end
+
+ it 'sorts each datafile' do
+ lines = IO.readlines(File.join(root_dir, 'cf', 'rubygems'))
+ expect(lines).to eql(lines.sort)
+ end
+
+ it 'builds an index that contains the seek address for the start of each line'
+ end
+ end
end