mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
tests: AppFlowy Cloud integration test (#4015)
* chore: save cloud ofnig * chore: fix .a link warnings * chore: add cloud test runner * refactor: test folder * ci: add test * ci: add test * ci: fix * ci: fix
This commit is contained in:
54
frontend/rust-lib/dart-ffi/src/appflowy_yaml.rs
Normal file
54
frontend/rust-lib/dart-ffi/src/appflowy_yaml.rs
Normal file
@ -0,0 +1,54 @@
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use flowy_server_config::af_cloud_config::AFCloudConfiguration;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct AppFlowyYamlConfiguration {
|
||||
cloud_config: Vec<AFCloudConfiguration>,
|
||||
}
|
||||
|
||||
pub fn save_appflowy_cloud_config(
|
||||
root: impl AsRef<Path>,
|
||||
new_config: &AFCloudConfiguration,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let file_path = root.as_ref().join("appflowy.yaml");
|
||||
let mut config = read_yaml_file(&file_path).unwrap_or_default();
|
||||
|
||||
if !config
|
||||
.cloud_config
|
||||
.iter()
|
||||
.any(|c| c.base_url == new_config.base_url)
|
||||
{
|
||||
config.cloud_config.push(new_config.clone());
|
||||
write_yaml_file(&file_path, &config)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn read_yaml_file(
|
||||
file_path: impl AsRef<Path>,
|
||||
) -> Result<AppFlowyYamlConfiguration, Box<dyn std::error::Error>> {
|
||||
let mut file = File::open(file_path)?;
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)?;
|
||||
let config: AppFlowyYamlConfiguration = serde_yaml::from_str(&contents)?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
fn write_yaml_file(
|
||||
file_path: impl AsRef<Path>,
|
||||
config: &AppFlowyYamlConfiguration,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let yaml_string = serde_yaml::to_string(config)?;
|
||||
let mut file = OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.open(file_path)?;
|
||||
file.write_all(yaml_string.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
use flowy_server_config::af_cloud_config::AFCloudConfiguration;
|
||||
@ -6,13 +8,17 @@ use flowy_server_config::AuthenticatorType;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct AppFlowyDartConfiguration {
|
||||
/// The root path of the application
|
||||
pub root: String,
|
||||
/// This path will be used to store the user data
|
||||
pub custom_app_path: String,
|
||||
pub origin_app_path: String,
|
||||
pub device_id: String,
|
||||
pub cloud_type: AuthenticatorType,
|
||||
pub authenticator_type: AuthenticatorType,
|
||||
pub(crate) supabase_config: SupabaseConfiguration,
|
||||
pub(crate) appflowy_cloud_config: AFCloudConfiguration,
|
||||
#[serde(default)]
|
||||
pub(crate) envs: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl AppFlowyDartConfiguration {
|
||||
@ -20,12 +26,13 @@ impl AppFlowyDartConfiguration {
|
||||
serde_json::from_str::<AppFlowyDartConfiguration>(s).unwrap()
|
||||
}
|
||||
|
||||
/// Parse the environment variable from the frontend application. The frontend will
|
||||
/// pass the environment variable as a json string after launching.
|
||||
pub fn write_env_from(env_str: &str) {
|
||||
let configuration = Self::from_str(env_str);
|
||||
configuration.cloud_type.write_env();
|
||||
configuration.appflowy_cloud_config.write_env();
|
||||
configuration.supabase_config.write_env();
|
||||
pub fn write_env(&self) {
|
||||
self.authenticator_type.write_env();
|
||||
self.appflowy_cloud_config.write_env();
|
||||
self.supabase_config.write_env();
|
||||
|
||||
for (k, v) in self.envs.iter() {
|
||||
std::env::set_var(k, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,11 @@ use tracing::{error, trace};
|
||||
use flowy_core::config::AppFlowyCoreConfig;
|
||||
use flowy_core::*;
|
||||
use flowy_notification::{register_notification_sender, unregister_all_notification_sender};
|
||||
use flowy_server_config::AuthenticatorType;
|
||||
use lib_dispatch::prelude::ToBytes;
|
||||
use lib_dispatch::prelude::*;
|
||||
|
||||
use crate::appflowy_yaml::save_appflowy_cloud_config;
|
||||
use crate::env_serde::AppFlowyDartConfiguration;
|
||||
use crate::notification::DartNotificationSender;
|
||||
use crate::{
|
||||
@ -20,6 +22,7 @@ use crate::{
|
||||
model::{FFIRequest, FFIResponse},
|
||||
};
|
||||
|
||||
mod appflowy_yaml;
|
||||
mod c;
|
||||
mod env_serde;
|
||||
mod model;
|
||||
@ -53,10 +56,11 @@ pub extern "C" fn init_sdk(data: *mut c_char) -> i64 {
|
||||
let c_str = unsafe { CStr::from_ptr(data) };
|
||||
let serde_str = c_str.to_str().unwrap();
|
||||
let configuration = AppFlowyDartConfiguration::from_str(serde_str);
|
||||
configuration.write_env();
|
||||
|
||||
configuration.cloud_type.write_env();
|
||||
configuration.appflowy_cloud_config.write_env();
|
||||
configuration.supabase_config.write_env();
|
||||
if configuration.authenticator_type == AuthenticatorType::AppFlowyCloud {
|
||||
let _ = save_appflowy_cloud_config(&configuration.root, &configuration.appflowy_cloud_config);
|
||||
}
|
||||
|
||||
let log_crates = vec!["flowy-ffi".to_string()];
|
||||
let config = AppFlowyCoreConfig::new(
|
||||
@ -170,8 +174,6 @@ pub extern "C" fn backend_log(level: i64, data: *const c_char) {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn set_env(data: *const c_char) {
|
||||
let c_str = unsafe { CStr::from_ptr(data) };
|
||||
let serde_str = c_str.to_str().unwrap();
|
||||
AppFlowyDartConfiguration::write_env_from(serde_str);
|
||||
pub extern "C" fn set_env(_data: *const c_char) {
|
||||
// Deprecated
|
||||
}
|
||||
|
Reference in New Issue
Block a user