Compare bytes and require http server to fix tests
This commit is contained in:
parent
af15bb536e
commit
818ec75498
|
@ -1,3 +1,5 @@
|
|||
require 'thrift/server/thin_http_server'
|
||||
|
||||
module Greeter
|
||||
class Handler
|
||||
def greeting(name)
|
||||
|
@ -41,4 +43,4 @@ module Greeter
|
|||
@server.serve()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,52 +21,52 @@ class SimpleTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_byte_encoding
|
||||
assert_equal "\xc7", S.pack_value(S::BYTE, 199)
|
||||
assert_equal "\xc7".bytes, S.pack_value(S::BYTE, 199).bytes
|
||||
end
|
||||
|
||||
def test_i16_encoding
|
||||
assert_equal "\x00\x96", S.pack_value(S::I16, 150)
|
||||
assert_equal "\x00\x96".bytes, S.pack_value(S::I16, 150).bytes
|
||||
end
|
||||
|
||||
def test_i32_encoding
|
||||
assert_equal "\x00\x96\xb4\x3f", S.pack_value(S::I32, 9876543)
|
||||
assert_equal "\x00\x96\xb4\x3f".bytes, S.pack_value(S::I32, 9876543).bytes
|
||||
end
|
||||
|
||||
def test_i64_encoding
|
||||
assert_equal "\x00\x00\x00\x1c\xbb\xf3\x09\x04", S.pack_value(S::I64, 123412351236)
|
||||
assert_equal "\x00\x00\x00\x1c\xbb\xf3\x09\x04".bytes, S.pack_value(S::I64, 123412351236).bytes
|
||||
end
|
||||
|
||||
def test_double_encoding
|
||||
assert_equal "\x40\x23\x00\x00\x00\x00\x00\x00", S.pack_value(S::DOUBLE, 9.5)
|
||||
assert_equal "\x40\x23\x00\x00\x00\x00\x00\x00".bytes, S.pack_value(S::DOUBLE, 9.5).bytes
|
||||
end
|
||||
|
||||
def test_string_encoding
|
||||
assert_equal "\x00\x00\x00\x05hello", S.pack_value(S::STRING, "hello")
|
||||
assert_equal "\x00\x00\x00\x05hello".bytes, S.pack_value(S::STRING, "hello").bytes
|
||||
end
|
||||
|
||||
def test_list_encoding
|
||||
assert_equal "\x08\x00\x00\x00\x03\x00\x00\x00\x17\x00\x00\x00\x16\x00\x00\x00\x15",
|
||||
S.pack_value(S::ListType.new(S::I32), [ 23, 22, 21 ])
|
||||
assert_equal "\x08\x00\x00\x00\x03\x00\x00\x00\x17\x00\x00\x00\x16\x00\x00\x00\x15".bytes,
|
||||
S.pack_value(S::ListType.new(S::I32), [ 23, 22, 21 ]).bytes
|
||||
end
|
||||
|
||||
def test_map_encoding
|
||||
assert_equal "\x0b\x08\x00\x00\x00\x01\x00\x00\x00\x03cat\x00\x00\x00\x05",
|
||||
S.pack_value(S::MapType.new(S::STRING, S::I32), "cat" => 5)
|
||||
assert_equal "\x0b\x08\x00\x00\x00\x01\x00\x00\x00\x03cat\x00\x00\x00\x05".bytes,
|
||||
S.pack_value(S::MapType.new(S::STRING, S::I32), "cat" => 5).bytes
|
||||
end
|
||||
|
||||
def test_set_encoding
|
||||
assert_equal "\x08\x00\x00\x00\x01\x00\x00\x00\x04",
|
||||
S.pack_value(S::SetType.new(S::I32), [ 4 ])
|
||||
assert_equal "\x08\x00\x00\x00\x01\x00\x00\x00\x04".bytes,
|
||||
S.pack_value(S::SetType.new(S::I32), [ 4 ]).bytes
|
||||
end
|
||||
|
||||
def test_struct_encoding
|
||||
assert_equal "\x0b\x00\x01\x00\x00\x00\x06Commie\x00",
|
||||
S.pack_value(S::StructType.new(Struct::ST_Example), Struct::ST_Example.new("Commie"))
|
||||
assert_equal "\x0b\x00\x01\x00\x00\x00\x06Commie\x00".bytes,
|
||||
S.pack_value(S::StructType.new(Struct::ST_Example), Struct::ST_Example.new("Commie")).bytes
|
||||
end
|
||||
|
||||
def test_request_encoding
|
||||
assert_equal "\x80\x01\x00\x01\x00\x00\x00\x09getHeight\x00\x00\x00\x17\x00",
|
||||
S.pack_request("getHeight", Struct::ST_Args.new, 23)
|
||||
assert_equal "\x80\x01\x00\x01\x00\x00\x00\x09getHeight\x00\x00\x00\x17\x00".bytes,
|
||||
S.pack_request("getHeight", Struct::ST_Args.new, 23).bytes
|
||||
end
|
||||
|
||||
## Decoding
|
||||
|
@ -89,12 +89,12 @@ class SimpleTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_i64_decoding
|
||||
assert_equal 123412351236,
|
||||
assert_equal 123412351236,
|
||||
S.read_value(StringIO.new("\x00\x00\x00\x1c\xbb\xf3\x09\x04"), S::I64)
|
||||
end
|
||||
|
||||
def test_double_decoding
|
||||
assert_equal 9.5,
|
||||
assert_equal 9.5,
|
||||
S.read_value(StringIO.new("\x40\x23\x00\x00\x00\x00\x00\x00"), S::DOUBLE)
|
||||
end
|
||||
|
||||
|
@ -103,31 +103,31 @@ class SimpleTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_list_decoding
|
||||
assert_equal [ 23, 22, 21 ],
|
||||
S.read_value(StringIO.new("\x08\x00\x00\x00\x03\x00\x00\x00\x17\x00\x00\x00\x16\x00\x00\x00\x15"),
|
||||
assert_equal [ 23, 22, 21 ],
|
||||
S.read_value(StringIO.new("\x08\x00\x00\x00\x03\x00\x00\x00\x17\x00\x00\x00\x16\x00\x00\x00\x15"),
|
||||
S::ListType.new(S::I32))
|
||||
end
|
||||
|
||||
def test_map_decoding
|
||||
assert_equal({ "cat" => 5 },
|
||||
S.read_value(StringIO.new("\x0b\x08\x00\x00\x00\x01\x00\x00\x00\x03cat\x00\x00\x00\x05"),
|
||||
assert_equal({ "cat" => 5 },
|
||||
S.read_value(StringIO.new("\x0b\x08\x00\x00\x00\x01\x00\x00\x00\x03cat\x00\x00\x00\x05"),
|
||||
S::MapType.new(S::STRING, S::I32)))
|
||||
end
|
||||
|
||||
def test_set_decoding
|
||||
assert_equal [ 4 ],
|
||||
S.read_value(StringIO.new("\x08\x00\x00\x00\x01\x00\x00\x00\x04"),
|
||||
assert_equal [ 4 ],
|
||||
S.read_value(StringIO.new("\x08\x00\x00\x00\x01\x00\x00\x00\x04"),
|
||||
S::ListType.new(S::I32))
|
||||
end
|
||||
|
||||
def test_struct_decoding
|
||||
assert_equal Struct::ST_Example.new("Commie"),
|
||||
S.read_value(StringIO.new("\x0b\x00\x01\x00\x00\x00\x06Commie\x00"),
|
||||
assert_equal Struct::ST_Example.new("Commie"),
|
||||
S.read_value(StringIO.new("\x0b\x00\x01\x00\x00\x00\x06Commie\x00"),
|
||||
S::StructType.new(Struct::ST_Example))
|
||||
end
|
||||
|
||||
def test_response_decoding
|
||||
assert_equal [ "getHeight", 255, 1 ],
|
||||
assert_equal [ "getHeight", 255, 1 ],
|
||||
S.read_response(
|
||||
StringIO.new("\x80\x01\x00\x02\x00\x00\x00\x09getHeight\x00\x00\x00\xff\x08\x00\x00\x00\x00\x00\x01\x00"),
|
||||
Struct::ST_Retval)
|
||||
|
|
Loading…
Reference in New Issue