#encoding: utf-8 require File.join(File.dirname(__FILE__), '..' , 'lib', 'simple_fs') require 'sequel' require 'digest/md5' describe SimpleFS, "一般操作" do before(:all) do @fs_path = '/tmp/fs' FileUtils.rm_rf @fs_path if Dir.exist? @fs_path @fs = SimpleFS::FS.new(@fs_path) @db = Sequel.sqlite File.join(@fs_path, 'index.db') end it "new" do Dir.exist?(File.join(@fs_path, 'pool')).should == true File.exist?(File.join(@fs_path, 'index.db')).should == true end it "create" do test_data = "This is test data." test_data_md5 = Digest::MD5.hexdigest(test_data) path = '/test' @fs.create path, test_data record = @db[:index].where(:path => '/test') record.count.should == 1 record.first[:path].should == path record.first[:file_id].should == test_data_md5 end it "copy" do old_path = '/test' new_path = '/test2' @fs.copy old_path, new_path record_old = @db[:index].where(:path => old_path).first record_new = @db[:index].where(:path => new_path).first record_new[:path].should == new_path record_new[:file_id].should == record_old[:file_id] end it "move" do old_path = '/test2' new_path = '/test2_mv' file_id = @db[:index].where(:path => old_path).first[:file_id] @fs.move old_path, new_path @db[:index].where(:path => old_path).count.should == 0 new_record = @db[:index].where(:path => new_path).first new_record[:file_id].should == file_id end it "remove" do path = "/test" @fs.remove path @db[:index].where(:path => path).count.should == 0 end end