Skip to content

Commit

Permalink
Fix clippy lints in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Feb 11, 2024
1 parent 5537749 commit 6d3667a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 54 deletions.
20 changes: 14 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ jobs:
profile: minimal
toolchain: stable
override: true
- run: cargo check
- uses: actions-rs/cargo@v1
with:
command: check

test:
name: Test (${{ matrix.os }})
Expand All @@ -40,9 +42,9 @@ jobs:
username: ${{ vars.NEON_ROLE }}
api_key: ${{ secrets.NEON_API_KEY }}
id: create-branch
- run: cargo test
env:
TEST_DB_URL: ${{ steps.create-branch.outputs.db_url }}
- uses: actions-rs/cargo@v1
with:
command: test
- uses: neondatabase/delete-branch-action@v3
if: always()
with:
Expand All @@ -61,7 +63,10 @@ jobs:
toolchain: stable
override: true
- run: rustup component add rustfmt
- run: cargo fmt --all -- --check
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
name: Clippy
Expand All @@ -74,4 +79,7 @@ jobs:
toolchain: stable
override: true
- run: rustup component add clippy
- run: cargo clippy -- -D warnings
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets -- -D warnings
7 changes: 4 additions & 3 deletions database/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,10 @@ mod tests {

// Return a database URL for each test
fn get_db_url() -> String {
std::env::var_os("TEST_DB_URL")
.map(|url| url.into_string().unwrap())
.unwrap_or(format!("postgresql://postgres@localhost/mailbox-test"))
std::env::var_os("TEST_DB_URL").map_or(
"postgresql://postgres@localhost/mailbox-test".to_string(),
|url| url.into_string().unwrap(),
)
}

// Helper for creating a NewMessage from its parts
Expand Down
78 changes: 33 additions & 45 deletions database/src/message_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,100 +116,88 @@ mod tests {

#[test]
fn test_matches_all() {
assert_eq!(MessageFilter::new().matches_all(), true);
assert_eq!(MessageFilter::new().with_ids(vec![1]).matches_all(), false);
assert_eq!(
MessageFilter::new()
assert!(MessageFilter::new().matches_all());
assert!(!MessageFilter::new().with_ids(vec![1]).matches_all());
assert!(
!MessageFilter::new()
.with_mailbox("foo".try_into().unwrap())
.matches_all(),
false
.matches_all()
);
assert_eq!(
MessageFilter::new()
assert!(
!MessageFilter::new()
.with_states(vec![State::Unread])
.matches_all(),
false
.matches_all()
);
}

#[test]
fn test_matches_message_empty_filter() {
let message = get_message();
assert_eq!(MessageFilter::new().matches_message(&message), true);
assert!(MessageFilter::new().matches_message(&message));
}

#[test]
fn test_matches_message_id_filter() {
let message = get_message();
assert_eq!(
assert!(
MessageFilter::new()
.with_ids(vec![1])
.matches_message(&message),
true
.matches_message(&message)
);
assert_eq!(
assert!(
MessageFilter::new()
.with_ids(vec![1, 2])
.matches_message(&message),
true
.matches_message(&message)
);
assert_eq!(
MessageFilter::new()
assert!(
!MessageFilter::new()
.with_ids(vec![2])
.matches_message(&message),
false
.matches_message(&message)
);
}

#[test]
fn test_matches_message_mailbox_filter() {
let message = get_message();
assert_eq!(
assert!(
MessageFilter::new()
.with_mailbox("parent".try_into().unwrap())
.matches_message(&message),
true
.matches_message(&message)
);
assert_eq!(
assert!(
MessageFilter::new()
.with_mailbox("parent/child".try_into().unwrap())
.matches_message(&message),
true
.matches_message(&message)
);
assert_eq!(
MessageFilter::new()
assert!(
!MessageFilter::new()
.with_mailbox("parent/child2".try_into().unwrap())
.matches_message(&message),
false
.matches_message(&message)
);
assert_eq!(
MessageFilter::new()
assert!(
!MessageFilter::new()
.with_mailbox("parent/child/grandchild".try_into().unwrap())
.matches_message(&message),
false
.matches_message(&message)
);
}

#[test]
fn test_matches_message_state_filter() {
let message = get_message();
assert_eq!(
assert!(
MessageFilter::new()
.with_states(vec![State::Unread])
.matches_message(&message),
true
.matches_message(&message)
);
assert_eq!(
assert!(
MessageFilter::new()
.with_states(vec![State::Unread, State::Read])
.matches_message(&message),
true
.matches_message(&message)
);
assert_eq!(
MessageFilter::new()
assert!(
!MessageFilter::new()
.with_states(vec![State::Read])
.matches_message(&message),
false
.matches_message(&message)
);
}
}

0 comments on commit 6d3667a

Please sign in to comment.