use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::http::ApiClient;
use crate::resources::AppResource;
#[derive(Debug, Serialize, Deserialize)]
pub struct AppLanguage {
pub name: String,
pub version: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UploadedApp {
pub id: String,
pub name: String,
pub description: Option<String>,
pub subdomain: Option<String>,
pub ram: u32,
pub cpu: f32,
pub language: AppLanguage,
}
impl UploadedApp {
pub fn into_resource(&self, api: ApiClient) -> AppResource {
AppResource::new(api, &self.id)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AppInfo {
pub name: String,
pub id: String,
pub owner: String,
pub cluster: String,
pub ram: u32,
pub language: String,
pub domain: Option<String>,
pub custom: Option<String>,
}
impl AppInfo {
pub fn into_resource(&self, api: ApiClient) -> AppResource {
AppResource::new(api, &self.id)
}
}
#[cfg(test)]
mod tests {
use super::{AppInfo, AppLanguage, UploadedApp};
use crate::http::ApiClient;
fn client() -> ApiClient {
unsafe { std::env::set_var("API_TOKEN", "test") };
ApiClient::new()
}
#[test]
fn uploaded_app_into_resource_binds_correct_id() {
let app = UploadedApp {
id: "app-abc".to_string(),
name: "test".to_string(),
description: None,
subdomain: None,
ram: 512,
cpu: 0.5,
language: AppLanguage {
name: "rust".to_string(),
version: "1.80".to_string(),
},
};
let resource = app.into_resource(client());
assert_eq!(resource.id, "app-abc");
}
#[test]
fn app_info_into_resource_binds_correct_id() {
let info = AppInfo {
id: "app-xyz".to_string(),
name: "test".to_string(),
owner: "owner".to_string(),
cluster: "us-east".to_string(),
ram: 256,
language: "rust".to_string(),
domain: None,
custom: None,
};
let resource = info.into_resource(client());
assert_eq!(resource.id, "app-xyz");
}
}
#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct AppLogs {
pub(crate) logs: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AppDomain {
pub app_id: String,
pub hostname: String,
#[serde(rename = "type")]
pub domain_type: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AppMetrics {
pub date: DateTime<Utc>,
pub cpu: f32,
pub ram: f32,
pub net: [u32; 2],
}