Skip to content

Commit 01dfbfc

Browse files
authored
Merge pull request #14 from lexara-prime-ai/dev
Dev
2 parents ae52b01 + bad7937 commit 01dfbfc

File tree

3 files changed

+90
-12
lines changed

3 files changed

+90
-12
lines changed

rust/src/main.rs

+71-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,82 @@ use tokio::main;
88
#[main]
99
async fn main() {
1010
/// List all Services.
11-
// let services = ServiceManager::list_all_services("20").await;
11+
let services = ServiceManager::list_all_services("20").await;
1212

1313
// List all Services by Name and Type.
14-
// let services = ServiceManager::find_service_by_name_and_type("whoami", "web_service").await;
14+
let services = ServiceManager::find_service_by_name_and_type("whoami", "web_service").await;
1515

1616
// List all Services by Region.
17-
// let services = ServiceManager::find_service_by_region("oregon", "10").await;
17+
let services = ServiceManager::find_service_by_region("oregon", "10").await;
1818

1919
// List all Services by Environment.
2020
let services = ServiceManager::find_service_by_environment("image", "10").await;
2121
}
22+
23+
/// Checks for regression of service management functions
24+
///
25+
/// These checks are there to validate that it is functioning properly
26+
/// and returning the right results, after which we shall describe each test case.
27+
/// List all Services.
28+
///
29+
/// This test confirms if the function list_all_services returns all services available.
30+
///
31+
/// #[tokio::test]
32+
/// async fn test_list_all_services() {
33+
/// let result = ServiceManager::list_all_services("10").await;
34+
/// // The result should be Ok().
35+
/// assert!(result.is_ok());
36+
///
37+
/// // Validate content.
38+
/// let services = result.unwrap();
39+
/// assert!(!services.is_empty());
40+
/// }
41+
///
42+
/// #[tokio::test]
43+
/// async fn test_find_service_by_name_and_type() {
44+
/// let result = ServiceManager::find_service_by_name_and_type("whoami", "web_service").await;
45+
/// // The result should be Ok().
46+
/// assert!(result.is_ok());
47+
/// // Validate content.
48+
/// let services = result.unwrap();
49+
/// assert!(!services.is_empty());
50+
/// }
51+
/// More tests...
52+
53+
#[cfg(test)]
54+
mod tests {
55+
use super::*;
56+
57+
#[tokio::test]
58+
async fn test_list_all_services() {
59+
let result = ServiceManager::list_all_services("10").await;
60+
// The result should be Ok().
61+
assert!(result.is_ok());
62+
63+
// Validate content.
64+
let services = result.unwrap();
65+
assert!(!services.is_empty());
66+
}
67+
68+
#[tokio::test]
69+
async fn test_find_service_by_name_and_type() {
70+
let result = ServiceManager::find_service_by_name_and_type("whoami", "web_service").await;
71+
// The result should be Ok().
72+
assert!(result.is_ok());
73+
74+
// Validate content.
75+
let services = result.unwrap();
76+
assert!(!services.is_empty());
77+
}
78+
79+
#[tokio::test]
80+
async fn test_find_service_by_region() {
81+
let result = ServiceManager::find_service_by_region("oregon", "10").await;
82+
// The result should be Ok().
83+
assert!(result.is_ok());
84+
85+
// Validate content.
86+
let services = result.unwrap();
87+
assert!(!services.is_empty());
88+
}
89+
}

rust/src/resource_management/services/service_manager.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@ const BASE_URL: &str = "https://api.render.com/v1";
1010
#[derive(Debug)]
1111
pub struct ServiceManager;
1212

13-
impl ServiceManager {
13+
14+
pub trait ServiceManagerOperations {
15+
fn list_all_services(limit: &str) -> impl std::future::Future<Output = Result<String, Error>> + Send;
16+
fn find_service_by_name_and_type(service_name: &str, service_type: &str) -> impl std::future::Future<Output = Result<String, Error>> + Send;
17+
fn find_service_by_region(service_region: &str, limit: &str) -> impl std::future::Future<Output = Result<String, Error>> + Send;
18+
fn find_service_by_environment(service_env: &str, limit: &str) -> impl std::future::Future<Output = Result<String, Error>> + Send;
19+
}
20+
21+
22+
impl ServiceManagerOperations for ServiceManager {
1423
/// List all resources.
15-
pub async fn list_all_services(limit: &str) -> Result<String, Error> {
24+
async fn list_all_services(limit: &str) -> Result<String, Error> {
1625
/*****************************************************
1726
*
1827
curl --request GET \
@@ -57,7 +66,7 @@ impl ServiceManager {
5766

5867
/// Finding services by type.
5968
/// Reqquired arguments: <service_type>
60-
pub async fn find_service_by_name_and_type(
69+
async fn find_service_by_name_and_type(
6170
service_name: &str,
6271
service_type: &str,
6372
) -> Result<String, Error> {
@@ -107,7 +116,7 @@ impl ServiceManager {
107116
}
108117

109118
/// Finding services by region.
110-
pub async fn find_service_by_region(
119+
async fn find_service_by_region(
111120
service_region: &str,
112121
limit: &str,
113122
) -> Result<String, Error> {
@@ -157,7 +166,7 @@ impl ServiceManager {
157166
}
158167

159168
/// Filtering for environments.
160-
pub async fn find_service_by_environment(
169+
async fn find_service_by_environment(
161170
service_env: &str,
162171
limit: &str,
163172
) -> Result<String, Error> {
@@ -181,8 +190,8 @@ impl ServiceManager {
181190
//////////////////////////////
182191
////// [DEBUG] logs. /////////
183192
//////////////////////////////
184-
println!("[REQUEST] -> {}", api_url);
185-
println!("[REQUEST] -> {}", api_key.clone());
193+
// println!("[REQUEST] -> {}", api_url);
194+
// println!("[REQUEST] -> {}", api_key.clone());
186195
//////////////////////////////
187196
let response = client
188197
.get(api_url)

rust/src/state/state.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
use anyhow::{Context, Error, Ok, Result};
33
use reqwest::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE};
44
use reqwest::{self};
5+
use std::sync::Arc;
56

67
use crate::environment_management::prelude::*;
78

89
#[allow(non_snake_case)]
910
#[derive(Debug)]
1011
pub struct State {
11-
pub CLIENT: reqwest::Client,
12+
pub CLIENT: Arc<reqwest::Client>,
1213
pub API_KEY: String,
1314
}
1415

@@ -19,7 +20,7 @@ impl State {
1920

2021
/// This method returns an instance of the applications current [State].
2122
Self {
22-
CLIENT: client,
23+
CLIENT: client.into(),
2324
API_KEY: api_key.trim().to_string(),
2425
}
2526
}

0 commit comments

Comments
 (0)