Skip to content

Commit

Permalink
Do some test cleanup
Browse files Browse the repository at this point in the history
- Name all test modules `tests`
- Use `use super::*` wherever possible
- Remove `test_` prefix from test method names
  • Loading branch information
spencewenski committed May 12, 2024
1 parent 0072e72 commit da1dfec
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
18 changes: 8 additions & 10 deletions src/auth/jwt/ietf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,23 @@ pub struct Claims {

#[cfg(test)]
mod tests {
use std::ops::{Add, Sub};
use std::str::FromStr;

use super::*;
use crate::auth::jwt::decode_auth_token;
use crate::util::serde_util::UriOrString;
use chrono::{TimeDelta, Utc};
use jsonwebtoken::{encode, EncodingKey, Header, TokenData};
use serde_derive::{Deserialize, Serialize};
use serde_json::from_str;
use std::ops::{Add, Sub};
use std::str::FromStr;
use url::Url;

use crate::auth::jwt::decode_auth_token;
use crate::auth::jwt::ietf::{Claims, Subject};
use crate::util::serde_util::UriOrString;

const TEST_JWT_SECRET: &str = "test-jwt-secret";
const AUDIENCE: &[&str] = &["authenticated"];
const REQUIRED_CLAIMS: &[&str] = &[];

#[test]
fn test_decode_token() {
fn decode_token() {
let jwt = build_token(false, None);

let decoded: TokenData<Claims> =
Expand All @@ -79,7 +77,7 @@ mod tests {
}

#[test]
fn test_decode_token_expired() {
fn decode_token_expired() {
let (_, jwt) = build_token(true, None);

let decoded: anyhow::Result<TokenData<Claims>> =
Expand All @@ -89,7 +87,7 @@ mod tests {
}

#[test]
fn test_decode_token_wrong_audience() {
fn decode_token_wrong_audience() {
let (_, jwt) = build_token(false, Some("different-audience".to_string()));

let decoded: anyhow::Result<TokenData<Claims>> =
Expand Down
2 changes: 1 addition & 1 deletion src/auth/jwt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub enum Subject {

#[cfg(test)]
mod tests {
use crate::auth::jwt::Subject;
use super::*;
use serde_derive::{Deserialize, Serialize};
use serde_json::from_str;
use std::str::FromStr;
Expand Down
2 changes: 1 addition & 1 deletion src/auth/jwt/openid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub enum Acr {

#[cfg(test)]
mod tests {
use crate::auth::jwt::openid::Acr;
use super::*;
use serde_derive::{Deserialize, Serialize};
use serde_json::from_str;
use std::str::FromStr;
Expand Down
4 changes: 2 additions & 2 deletions src/config/service/http/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ impl<T: Default> InitializerConfig<T> {
}

#[cfg(test)]
mod test {
mod tests {
use super::*;
use serde_json::Value;

#[test]
fn test_custom_config() {
fn custom_config() {
// Note: since we're parsing into a Initializer config struct directly, we don't
// need to prefix `foo` with `initializer`. If we want to actually provide custom initializer
// configs, the table key will need to be `[initializer.foo]`.
Expand Down
4 changes: 2 additions & 2 deletions src/config/service/http/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ impl<T: Default> MiddlewareConfig<T> {
}

#[cfg(test)]
mod test {
mod tests {
use super::*;
use serde_json::Value;

#[test]
fn test_custom_config() {
fn custom_config() {
// Note: since we're parsing into a Middleware config struct directly, we don't
// need to prefix `foo` with `middleware`. If we want to actually provide custom middleware
// configs, the table key will need to be `[middleware.foo]`.
Expand Down
5 changes: 2 additions & 3 deletions src/service/http/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,12 @@ impl HttpService {

#[cfg(test)]
mod tests {
use aide::axum::routing::get;

#[test]
#[cfg(feature = "open-api")]
fn list_routes() {
use crate::service::http::service::HttpService;
use aide::axum::routing::{delete_with, get_with, post_with, put_with};
use super::*;
use aide::axum::routing::{delete_with, get, get_with, post_with, put_with};
use aide::axum::ApiRouter;
use aide::openapi::OpenApi;
use itertools::Itertools;
Expand Down

0 comments on commit da1dfec

Please sign in to comment.