Skip to content

Commit

Permalink
Add tests to CI step, improve tests
Browse files Browse the repository at this point in the history
We include a test step in the GHA workflow file, and unwrap the
Results in test assertions to simplify the code.
  • Loading branch information
adamnfish committed Jan 12, 2024
1 parent a1037eb commit 5bb36e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ jobs:
rust-version: 1.58
- name: Build
run: cargo build
- name: Test
run: cargo test
20 changes: 4 additions & 16 deletions src/google.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,36 +62,24 @@ mod tests {
#[test]
fn test_build_threaded_webhook_with_placeholder() {
let result = GoogleChatMessage::build_webhook_url(&String::from("https://example.com/ABCDEF?threadKey={threadKey}"), &String::from("1234"));
match result {
Ok(url) => assert_eq!(url, String::from("https://example.com/ABCDEF?messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD&threadKey=1234")),
Err(_) => assert!(false),
}
assert_eq!(Result::unwrap(result), String::from("https://example.com/ABCDEF?messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD&threadKey=1234"))
}

#[test]
fn test_build_threaded_webhook_without_placeholder() {
let result = GoogleChatMessage::build_webhook_url(&String::from("https://example.com/ABCDEF"), &String::from("1234"));
match result {
Ok(url) => assert_eq!(url, String::from("https://example.com/ABCDEF?messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD&threadKey=1234")),
Err(_) => assert!(false),
}
assert_eq!(Result::unwrap(result), String::from("https://example.com/ABCDEF?messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD&threadKey=1234"))
}

#[test]
fn test_preserves_other_existing_params() {
let result = GoogleChatMessage::build_webhook_url(&String::from("https://example.com/ABCDEF?foo=bar"), &String::from("1234"));
match result {
Ok(url) => assert_eq!(url, String::from("https://example.com/ABCDEF?foo=bar&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD&threadKey=1234")),
Err(_) => assert!(false),
}
assert_eq!(Result::unwrap(result), String::from("https://example.com/ABCDEF?foo=bar&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD&threadKey=1234"))
}

#[test]
fn test_overrides_existing_messagereplyoption_parameter() {
let result = GoogleChatMessage::build_webhook_url(&String::from("https://example.com/ABCDEF?messageReplyOption=REPLY_MESSAGE"), &String::from("1234"));
match result {
Ok(url) => assert_eq!(url, String::from("https://example.com/ABCDEF?messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD&threadKey=1234")),
Err(_) => assert!(false),
}
assert_eq!(Result::unwrap(result), String::from("https://example.com/ABCDEF?messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD&threadKey=1234"))
}
}

0 comments on commit 5bb36e9

Please sign in to comment.