Skip to content

Commit

Permalink
Add tests for GatewayMessage to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfl0wer committed Nov 22, 2023
1 parent 8a55376 commit e756999
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions tests/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod common;

use std::sync::{Arc, RwLock};

use chorus::errors::GatewayError;
use chorus::gateway::*;
use chorus::types::{self, ChannelModifySchema, RoleCreateModifySchema, RoleObject};
// PRETTYFYME: Move common wasm setup to common.rs
Expand Down Expand Up @@ -125,3 +126,92 @@ async fn test_recursive_self_updating_structs() {
assert_eq!(guild_role_inner.name, "yippieee".to_string());
common::teardown(bundle).await;
}

#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn test_error() {
let error = GatewayMessage("4000".to_string()).error().unwrap();
assert_eq!(error, GatewayError::Unknown);
let error = GatewayMessage("4001".to_string()).error().unwrap();
assert_eq!(error, GatewayError::UnknownOpcode);
let error = GatewayMessage("4002".to_string()).error().unwrap();
assert_eq!(error, GatewayError::Decode);
let error = GatewayMessage("4003".to_string()).error().unwrap();
assert_eq!(error, GatewayError::NotAuthenticated);
let error = GatewayMessage("4004".to_string()).error().unwrap();
assert_eq!(error, GatewayError::AuthenticationFailed);
let error = GatewayMessage("4005".to_string()).error().unwrap();
assert_eq!(error, GatewayError::AlreadyAuthenticated);
let error = GatewayMessage("4007".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidSequenceNumber);
let error = GatewayMessage("4008".to_string()).error().unwrap();
assert_eq!(error, GatewayError::RateLimited);
let error = GatewayMessage("4009".to_string()).error().unwrap();
assert_eq!(error, GatewayError::SessionTimedOut);
let error = GatewayMessage("4010".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidShard);
let error = GatewayMessage("4011".to_string()).error().unwrap();
assert_eq!(error, GatewayError::ShardingRequired);
let error = GatewayMessage("4012".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidAPIVersion);
let error = GatewayMessage("4013".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidIntents);
let error = GatewayMessage("4014".to_string()).error().unwrap();
assert_eq!(error, GatewayError::DisallowedIntents);
}

#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn test_error_message() {
let error = GatewayMessage("Unknown Error".to_string()).error().unwrap();
assert_eq!(error, GatewayError::Unknown);
let error = GatewayMessage("Unknown Opcode".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::UnknownOpcode);
let error = GatewayMessage("Decode Error".to_string()).error().unwrap();
assert_eq!(error, GatewayError::Decode);
let error = GatewayMessage("Not Authenticated".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::NotAuthenticated);
let error = GatewayMessage("Authentication Failed".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::AuthenticationFailed);
let error = GatewayMessage("Already Authenticated".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::AlreadyAuthenticated);
let error = GatewayMessage("Invalid Seq".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidSequenceNumber);
let error = GatewayMessage("Rate Limited".to_string()).error().unwrap();
assert_eq!(error, GatewayError::RateLimited);
let error = GatewayMessage("Session Timed Out".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::SessionTimedOut);
let error = GatewayMessage("Invalid Shard".to_string()).error().unwrap();
assert_eq!(error, GatewayError::InvalidShard);
let error = GatewayMessage("Sharding Required".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::ShardingRequired);
let error = GatewayMessage("Invalid API Version".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::InvalidAPIVersion);
let error = GatewayMessage("Invalid Intent(s)".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::InvalidIntents);
let error = GatewayMessage("Disallowed Intent(s)".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::DisallowedIntents);
// Also test the dot thing
let error = GatewayMessage("Invalid Intent(s).".to_string())
.error()
.unwrap();
assert_eq!(error, GatewayError::InvalidIntents);
}

0 comments on commit e756999

Please sign in to comment.