Sha256: 3128864c83c477beee4ee23622a7b3ae40ff54d58559ee8fb2792eb99bc6a656

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

#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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_fs-0.0.1 spec/simple_fs_spec.rb