Rakefile: kill raa_update task
[metropolis.git] / test / test_tdb.rb
blob3f607d1be7eda9e0d5fbac2b23956305328713af
1 # -*- encoding: binary -*-
2 require './test/rack_read_write.rb'
3 $-w = true
4 require 'metropolis'
6 class Test_TDB < Test::Unit::TestCase
7   attr_reader :tmp, :o, :uri
8   include TestRackReadWrite
10   def setup
11     tmp = Tempfile.new('tdb')
12     @path_pattern = tmp.path + ".%01x.tdb"
13     tmp.close!
14     @uri = "tdb:///"
15     @app_opts = { :uri => @uri, :path_pattern => @path_pattern }
16   end
18   def test_alternate_hash
19     n = 7
20     @app = Metropolis.new(@app_opts.merge(:nr_slots => n, :multi_hash => :to_i))
21     req = Rack::MockRequest.new(app)
22     o = { :lint => true, :fatal => true, :input => "." }
23     (1..8).each do |i|
24       r = req.put("/#{i * n}", o)
25       assert_equal 201, r.status
26       assert_equal "Created\n", r.body
27     end
28     tmp = Hash.new { |h,k| h[k] = {} }
29     @app.instance_eval do
30       @dbv.each_with_index { |db,i| db.each { |k,v| tmp[i][k] = v } }
31     end
32     expect = {
33       0 => {
34         "7" => ".",
35         "14" => ".",
36         "21" => ".",
37         "28" => ".",
38         "35" => ".",
39         "42" => ".",
40         "49" => ".",
41         "56" => ".",
42       }
43     }
44     assert_equal expect, tmp
45   end
47   def teardown
48     Dir[@path_pattern.sub!(/%\d*x/, '*')].each { |x| File.unlink(x) }
49   end
50 end