From bc0017c6b79a2984cfdcf9500603e94ea88b59bc Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Tue, 21 May 2024 13:15:19 +0200 Subject: [PATCH] Properly removes test database directories. --- spec/test-ships.cr | 49 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/spec/test-ships.cr b/spec/test-ships.cr index 0200373..979a597 100644 --- a/spec/test-ships.cr +++ b/spec/test-ships.cr @@ -16,6 +16,8 @@ describe "DODB::DataBase" do end db.to_a.sort.should eq(Ship.all_ships.sort) + + db.rm_storage_dir end it "rewrite already stored data" do @@ -28,6 +30,8 @@ describe "DODB::DataBase" do db[key] = ship db[key].should eq(ship) + + db.rm_storage_dir end it "properly remove data" do @@ -49,6 +53,8 @@ describe "DODB::DataBase" do db[i]?.should be_nil end + + db.rm_storage_dir end it "preserves data on reopening" do @@ -61,6 +67,9 @@ describe "DODB::DataBase" do db2 << Ship.mutsuki db1.to_a.size.should eq(2) + + db1.rm_storage_dir + db2.rm_storage_dir end it "iterates in normal and reversed order" do @@ -81,6 +90,8 @@ describe "DODB::DataBase" do # Actual reversal is tested here. db.to_a(reversed: true).should eq db.to_a.reverse + + db.rm_storage_dir end it "respects the provided offsets if any" do @@ -97,6 +108,8 @@ describe "DODB::DataBase" do db.to_a(offset: 0, limit: 3).should eq [ Ship.mutsuki, Ship.kisaragi, Ship.yayoi ] + + db.rm_storage_dir end end @@ -113,6 +126,8 @@ describe "DODB::DataBase" do Ship.all_ships.each_with_index do |ship| db_ships_by_name.get?(ship.name).should eq(ship) end + + db.rm_storage_dir end it "raise on index overload" do @@ -127,6 +142,8 @@ describe "DODB::DataBase" do expect_raises(DODB::IndexOverload) do db << Ship.kisaragi end + + db.rm_storage_dir end it "properly deindex" do @@ -145,6 +162,8 @@ describe "DODB::DataBase" do Ship.all_ships.each do |ship| db_ships_by_name.get?(ship.name).should be_nil end + + db.rm_storage_dir end it "properly reindex" do @@ -163,6 +182,8 @@ describe "DODB::DataBase" do db[key].should eq(some_new_ship) db_ships_by_name.get?(some_new_ship.name).should eq(some_new_ship) + + db.rm_storage_dir end it "properly updates" do @@ -183,6 +204,8 @@ describe "DODB::DataBase" do db_ships_by_name.get?("Kisaragi").should be_nil db_ships_by_name.get?(new_kisaragi.name).should eq new_kisaragi + + db.rm_storage_dir end end @@ -213,6 +236,8 @@ describe "DODB::DataBase" do end db_ships_by_class.get?("does-not-exist").should be_nil + + db.rm_storage_dir end it "removes select elements from partitions" do @@ -231,6 +256,8 @@ describe "DODB::DataBase" do partition.any?(&.name.==("Kisaragi")).should be_false end + + db.rm_storage_dir end end @@ -254,6 +281,8 @@ describe "DODB::DataBase" do # There shouldn’t be one in our data about WWII Japanese warships… db_ships_by_tags.get?("starship").should be_nil + + db.rm_storage_dir end it "properly removes tags" do @@ -278,6 +307,8 @@ describe "DODB::DataBase" do # end db_ships_by_tags.get("flagship").should eq([] of Ship) + + db.rm_storage_dir end it "gets items that have multiple tags" do @@ -297,6 +328,8 @@ describe "DODB::DataBase" do results = db_ships_by_tags.get(["flagship"]) results.should eq([Ship.yamato]) + + db.rm_storage_dir end end @@ -319,6 +352,8 @@ describe "DODB::DataBase" do results.should eq(ship) end end + + db.rm_storage_dir end end @@ -340,11 +375,12 @@ describe "DODB::DataBase" do db_ships_by_name.get?(ship.name).should eq(ship) db_ships_by_class.get(ship.klass).should contain(ship) end + + db.rm_storage_dir end it "migrates properly" do - ::FileUtils.rm_rf "test-storage-migration-origin" - old_db = DODB::DataBase(PrimitiveShip).new "test-storage-migration-origin" + old_db = DODB::SpecDataBase(PrimitiveShip).new "-migration-origin" old_ships_by_name = old_db.new_index "name", &.name old_ships_by_class = old_db.new_partition "class", &.class_name @@ -384,6 +420,9 @@ describe "DODB::DataBase" do ship.tags.any?(&.==("name ship")).should be_true if ship.name == ship.klass end + + old_db.rm_storage_dir + new_db.rm_storage_dir end end @@ -410,6 +449,8 @@ describe "DODB::DataBase" do dump = db.to_a dump.size.should eq fork_count * entries_per_fork + + db.rm_storage_dir end it "works for updating values" do @@ -448,6 +489,8 @@ describe "DODB::DataBase" do entry.tags.should eq ["updated"] end end + + db.rm_storage_dir end it "does parallel-safe updates" do @@ -473,6 +516,8 @@ describe "DODB::DataBase" do processes.each &.wait db_entries_by_name.get("test").klass.should eq((fork_count * entries_per_fork).to_s) + + db.rm_storage_dir end end end