THRIFT-3592 Add basic test client
This closes #830
diff --git a/test/lua/test_basic_client.lua b/test/lua/test_basic_client.lua
index e7571f9..5e0966f 100644
--- a/test/lua/test_basic_client.lua
+++ b/test/lua/test_basic_client.lua
@@ -17,6 +17,8 @@
require('TSocket')
+require('TBufferedTransport')
+require('TFramedTransport')
require('TBinaryProtocol')
require('ThriftTest_ThriftTest')
require('liblualongnumber')
@@ -25,28 +27,56 @@
function teardown()
if client then
- -- Shuts down the server
- client:testVoid()
-
-- close the connection
client:close()
end
end
+function parseArgs(rawArgs)
+ local opt = {
+ protocol='binary',
+ transport='buffered',
+ port='9090',
+ }
+ for i, str in pairs(rawArgs) do
+ if i > 0 then
+ k, v = string.match(str, '--(%w+)=(%w+)')
+ assert(opt[k] ~= nil, 'Unknown argument')
+ opt[k] = v
+ end
+ end
+ return opt
+end
+
function assertEqual(val1, val2, msg)
assert(val1 == val2, msg)
end
-function testBasicClient()
+function testBasicClient(rawArgs)
+ local opt = parseArgs(rawArgs)
local socket = TSocket:new{
- port = 9090
+ port = tonumber(opt.port)
}
assert(socket, 'Failed to create client socket')
socket:setTimeout(5000)
- local protocol = TBinaryProtocol:new{
+ local transports = {
+ buffered = TBufferedTransport,
+ framed = TFramedTransport,
+ }
+ assert(transports[opt.transport] ~= nil)
+ local transport = transports[opt.transport]:new{
trans = socket
}
+
+ local protocols = {
+ binary = TBinaryProtocol,
+ -- compact = TCompactProtocol,
+ }
+ assert(protocols[opt.protocol] ~= nil)
+ local protocol = protocols[opt.protocol]:new{
+ trans = transport
+ }
assert(protocol, 'Failed to create binary protocol')
client = ThriftTestClient:new{
@@ -62,6 +92,10 @@
assertEqual(client:testString('lala'), 'lala', 'Failed testString')
assertEqual(client:testString('wahoo'), 'wahoo', 'Failed testString')
+ -- Bool
+ assertEqual(client:testBool(true), true, 'Failed testBool true')
+ -- assertEqual(client:testBool(false), false, 'Failed testBool false')
+
-- Byte
assertEqual(client:testByte(0x01), 1, 'Failed testByte 1')
assertEqual(client:testByte(0x40), 64, 'Failed testByte 2')
@@ -130,9 +164,8 @@
-- TODO fix client struct equality
--assertEqual(client:testStruct(a), a, 'Failed testStruct')
- -- Call the void function and end the test (handler stops server)
- client:testVoid()
+ -- TODO add list map set exception etc etc
end
-testBasicClient()
-teardown()
\ No newline at end of file
+testBasicClient(arg)
+teardown()