Skip to content
This repository was archived by the owner on Mar 18, 2022. It is now read-only.
This repository was archived by the owner on Mar 18, 2022. It is now read-only.

Refactor server::tests #55

@tbmreza

Description

@tbmreza

context: https://github.com/Qovery/RedisLess/blob/main/redisless/src/server/tests/mod.rs

I have been trying rstest crate that I just learned from another project. I managed to get the following test passes:

#[rstest]
#[case::incr_by_1(
    3001_u16,
    vec![ 
        // precondition:
        con_set(23, 45),
        // test subject:
        con_incr(23, 1),
    ],
    vec![ 
        assert_con_exists(23, true),
        assert_con_get(23, 46),
    ]
)]
fn redis_client(
    #[case] port: u16,
    #[case] commands: Vec<Box<dyn for<'r> Fn(&'r mut Connection)>>,
    #[case] assertions: Vec<Box<dyn for<'r> Fn(&'r mut Connection)>>,
){
    let (server, mut con) = get_server_connection(port);
    commands.iter().for_each(|f| f(&mut con));
    assertions.iter().for_each(|f| f(&mut con));
    assert_eq!(server.stop(), Some(ServerState::Stopped));
}

To declare, for example, a delete command test case, insert the following attribute:

#[case::del_existent_key(
    3002_u16,
    vec![ 
        // precondition:
        con_set(23, 45),
        // test subject:
        con_del(23),
    ],
    vec![ 
        assert_con_exists(23, false),
    ]
)]

If anyone thinks this interface will get a long way, I'll be happy to line up a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions