mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	 c9df7b0557
			
		
	
	c9df7b0557
	
	
	
		
			
			Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
		
			
				
	
	
		
			64 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use std::sync::{atomic, Arc};
 | |
| 
 | |
| use router::{configs::settings::Settings, routes, services};
 | |
| 
 | |
| mod utils;
 | |
| 
 | |
| #[tokio::test]
 | |
| #[should_panic]
 | |
| #[allow(clippy::unwrap_used)]
 | |
| async fn get_redis_conn_failure() {
 | |
|     // Arrange
 | |
|     utils::setup().await;
 | |
|     let (tx, _) = tokio::sync::oneshot::channel();
 | |
|     let app_state = Box::pin(routes::AppState::new(
 | |
|         Settings::default(),
 | |
|         tx,
 | |
|         Box::new(services::MockApiClient),
 | |
|     ))
 | |
|     .await;
 | |
|     let state = Arc::new(app_state)
 | |
|         .get_session_state(
 | |
|             &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(),
 | |
|             || {},
 | |
|         )
 | |
|         .unwrap();
 | |
| 
 | |
|     let _ = state.store.get_redis_conn().map(|conn| {
 | |
|         conn.is_redis_available
 | |
|             .store(false, atomic::Ordering::SeqCst)
 | |
|     });
 | |
| 
 | |
|     // Act
 | |
|     let _ = state.store.get_redis_conn();
 | |
| 
 | |
|     // Assert
 | |
|     // based on #[should_panic] attribute
 | |
| }
 | |
| 
 | |
| #[tokio::test]
 | |
| #[allow(clippy::unwrap_used)]
 | |
| async fn get_redis_conn_success() {
 | |
|     // Arrange
 | |
|     Box::pin(utils::setup()).await;
 | |
|     let (tx, _) = tokio::sync::oneshot::channel();
 | |
|     let app_state = Box::pin(routes::AppState::new(
 | |
|         Settings::default(),
 | |
|         tx,
 | |
|         Box::new(services::MockApiClient),
 | |
|     ))
 | |
|     .await;
 | |
|     let state = Arc::new(app_state)
 | |
|         .get_session_state(
 | |
|             &common_utils::id_type::TenantId::try_from_string("public".to_string()).unwrap(),
 | |
|             || {},
 | |
|         )
 | |
|         .unwrap();
 | |
| 
 | |
|     // Act
 | |
|     let result = state.store.get_redis_conn();
 | |
| 
 | |
|     // Assert
 | |
|     assert!(result.is_ok())
 | |
| }
 |