1- mod utils;
2-
31use anyhow:: Context ;
42use anyhow:: Result ;
53use redis:: RedisError ;
4+
65use utils:: { get_redis_connection, start_redis_server_with_module} ;
76
7+ mod utils;
8+
89#[ test]
910fn test_hello ( ) -> Result < ( ) > {
10- let _guards = vec ! [ start_redis_server_with_module( "hello" , 6479 )
11+ let port: u16 = 6479 ;
12+ let _guards = vec ! [ start_redis_server_with_module( "hello" , port)
1113 . with_context( || "failed to start redis server" ) ?] ;
1214 let mut con =
13- get_redis_connection ( 6479 ) . with_context ( || "failed to connect to redis server" ) ?;
15+ get_redis_connection ( port ) . with_context ( || "failed to connect to redis server" ) ?;
1416
1517 let res: Vec < i32 > = redis:: cmd ( "hello.mul" )
1618 . arg ( & [ 3 , 4 ] )
@@ -29,10 +31,11 @@ fn test_hello() -> Result<()> {
2931
3032#[ test]
3133fn test_keys_pos ( ) -> Result < ( ) > {
32- let _guards = vec ! [ start_redis_server_with_module( "keys_pos" , 6480 )
34+ let port: u16 = 6480 ;
35+ let _guards = vec ! [ start_redis_server_with_module( "keys_pos" , port)
3336 . with_context( || "failed to start redis server" ) ?] ;
3437 let mut con =
35- get_redis_connection ( 6480 ) . with_context ( || "failed to connect to redis server" ) ?;
38+ get_redis_connection ( port ) . with_context ( || "failed to connect to redis server" ) ?;
3639
3740 let res: Vec < String > = redis:: cmd ( "keys_pos" )
3841 . arg ( & [ "a" , "1" , "b" , "2" ] )
@@ -43,23 +46,46 @@ fn test_keys_pos() -> Result<()> {
4346 let res: Result < Vec < String > , RedisError > =
4447 redis:: cmd ( "keys_pos" ) . arg ( & [ "a" , "1" , "b" ] ) . query ( & mut con) ;
4548 if res. is_ok ( ) {
46- return Err ( anyhow:: Error :: msg ( "Shuold return an error" ) ) ;
49+ return Err ( anyhow:: Error :: msg ( "Should return an error" ) ) ;
4750 }
4851
4952 Ok ( ( ) )
5053}
5154
55+ #[ test]
56+ fn test_test_helper_version ( ) -> Result < ( ) > {
57+ let port: u16 = 6481 ;
58+ let _guards = vec ! [ start_redis_server_with_module( "test_helper" , port)
59+ . with_context( || "failed to start redis server" ) ?] ;
60+ let mut con =
61+ get_redis_connection ( port) . with_context ( || "failed to connect to redis server" ) ?;
62+
63+ let res: Vec < i64 > = redis:: cmd ( "test_helper.version" )
64+ . query ( & mut con)
65+ . with_context ( || "failed to run test_helper.version" ) ?;
66+ assert ! ( res[ 0 ] > 0 ) ;
67+
68+ // Test also an internal implementation that might not always be reached
69+ let res2: Vec < i64 > = redis:: cmd ( "test_helper._version_rm_call" )
70+ . query ( & mut con)
71+ . with_context ( || "failed to run test_helper._version_rm_call" ) ?;
72+ assert_eq ! ( res, res2) ;
73+
74+ Ok ( ( ) )
75+ }
76+
5277#[ test]
5378fn test_hello_info ( ) -> Result < ( ) > {
54- let _guards = vec ! [ start_redis_server_with_module( "hello" , 6481 )
79+ let port: u16 = 6482 ;
80+ let _guards = vec ! [ start_redis_server_with_module( "hello" , port)
5581 . with_context( || "failed to start redis server" ) ?] ;
5682 let mut con =
57- get_redis_connection ( 6481 ) . with_context ( || "failed to connect to redis server" ) ?;
83+ get_redis_connection ( port ) . with_context ( || "failed to connect to redis server" ) ?;
5884
5985 let res: String = redis:: cmd ( "INFO" )
6086 . arg ( "HELLO" )
6187 . query ( & mut con)
62- . with_context ( || "failed to run hello.mul " ) ?;
88+ . with_context ( || "failed to run INFO HELLO " ) ?;
6389 assert ! ( res. contains( "hello_field:hello_value" ) ) ;
6490
6591 Ok ( ( ) )
@@ -68,10 +94,11 @@ fn test_hello_info() -> Result<()> {
6894#[ allow( unused_must_use) ]
6995#[ test]
7096fn test_hello_err ( ) -> Result < ( ) > {
71- let _guards = vec ! [ start_redis_server_with_module( "hello" , 6482 )
97+ let port: u16 = 6483 ;
98+ let _guards = vec ! [ start_redis_server_with_module( "hello" , port)
7299 . with_context( || "failed to start redis server" ) ?] ;
73100 let mut con =
74- get_redis_connection ( 6482 ) . with_context ( || "failed to connect to redis server" ) ?;
101+ get_redis_connection ( port ) . with_context ( || "failed to connect to redis server" ) ?;
75102
76103 // Make sure embedded nulls do not cause a crash
77104 redis:: cmd ( "hello.err" )
0 commit comments