Skip to content

Conversation

faern
Copy link
Member

@faern faern commented Jun 27, 2024

Follow up to #102. I realized we also used error-chain in tests 🤦. So a step in the direction of removing error-chain completely is to stop using it in tests. I just replaced most error handling with expect, since expect/unwrap is all we did with the errors we had anyway.

Since a lot of the test helper methods became infallible, sadly virtually every test was affected, due to them using the test helpers.


This change is Reviewable

@faern faern requested a review from dlon June 27, 2024 08:05
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 8 of 8 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @faern)


tests/redirect_rules.rs line 52 at r1 (raw file):

        assert_matches!(pf.flush_rules(ANCHOR_NAME, pfctl::RulesetKind::Redirect), Ok(()));
        assert_eq!(
            pfcli::get_nat_rules(ANCHOR_NAME),

Nit: I think you could replace this with assert!(pfctl::get_nat_rules(ANCHOR_NAME).is_empty()) or assert_eq!(pfctl::get_nat_rules(ANCHOR_NAME).len(), 0).

Copy link
Member Author

@faern faern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dlon)


tests/redirect_rules.rs line 52 at r1 (raw file):

Previously, dlon (David Lönnhager) wrote…

Nit: I think you could replace this with assert!(pfctl::get_nat_rules(ANCHOR_NAME).is_empty()) or assert_eq!(pfctl::get_nat_rules(ANCHOR_NAME).len(), 0).

I can, but it would yield worse error messages. Then it would either just say that my bool was false, or it would say my number was not zero. With this construct the panic message will contain the rules returned (that was not an empty list).

@faern faern merged commit b1e5d05 into main Jun 27, 2024
@faern faern deleted the remove-error-chain-from-tests branch June 27, 2024 09:26
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 this pull request may close these issues.

2 participants