Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test utilities can be improved #115

Closed
sargarass opened this issue Oct 31, 2023 · 1 comment
Closed

Test utilities can be improved #115

sargarass opened this issue Oct 31, 2023 · 1 comment

Comments

@sargarass
Copy link
Contributor

For now, Elfo provides us with assert_msg_eq and assert_msg, which support assertions for specific message types and values inside. However, these assertions do not offer the capability to unpack the message and bind it to a value. Therefore, I suggest that we introduce the expect_x functions to handle these cases in the test environment.

#[track_caller]
pub fn expect_message<T: Message>(msg: Envelope) -> T {
    msg!(match msg {
        msg @ T => msg,
        msg => panic!(
            "unexpected message: expected {}, got: {:?}",
            elfo::dumping::extract_name_by_type::<T>(),
            msg
        ),
    })
}

#[track_caller]
pub fn expect_request<T: Request>(msg: Envelope) -> (T, ResponseToken<T>) {
    msg!(match msg {
        (msg @ T, token) => (msg, token),
        msg => panic!(
            "unexpected request: expected {}, got: {:?}",
            elfo::dumping::extract_name_by_type::<T>(),
            msg
        ),
    })
}

Note that all of these functions return the unpacked value to a user.

@sargarass
Copy link
Contributor Author

we got it here PR121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant