Skip to content

Commit 6584558

Browse files
committed
make it easy to run tests, add spa-client, spa-server unit test to ci
1 parent e106ffb commit 6584558

File tree

12 files changed

+50
-46
lines changed

12 files changed

+50
-46
lines changed

.github/workflows/spa-server-ci.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ jobs:
3030
key: cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
3131
- name: build all
3232
run: cargo build
33-
- name: run server ci
33+
- name: run spa-client test
34+
run: cargo test -p spa-client
35+
- name: run spa-client test
36+
run: cargo test -p spa-server
37+
- name: run integration test
3438
# --show-output
3539
run: cargo test -p tests --test starter -j 1 -- --test-threads 1

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spa-client"
3-
version = "2.2.2"
3+
version = "2.2.3"
44
edition = "2021"
55
authors = ["timzaak"]
66
license = "MIT"

client/src/api.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -191,25 +191,28 @@ mod test {
191191
use crate::api::API;
192192
use spa_server::admin_server::request::UpdateUploadingStatusOption;
193193
use spa_server::domain_storage::UploadingStatus;
194-
use spa_server::LOCAL_HOST;
194+
use crate::LOCAL_HOST;
195195

196196
fn get_api() -> API {
197197
let config = crate::config::test::default_local_config().unwrap();
198198
API::new(&config).unwrap()
199199
}
200+
#[ignore]
200201
#[tokio::test]
201202
async fn get_domain_info() {
202203
let api = get_api();
203204
let response = api.get_domain_info(None).await.unwrap();
204205
println!("{:?}", response);
205206
}
206207

208+
#[ignore]
207209
#[tokio::test]
208210
async fn get_file_metadata() {
209211
let api = get_api();
210212
let r = api.get_file_metadata(LOCAL_HOST, 1).await;
211213
println!("{:?}", r);
212214
}
215+
#[ignore]
213216
#[tokio::test]
214217
async fn update_upload_status() {
215218
let api = get_api();

client/src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ async fn run_with_commands(commands: CliCommand) -> anyhow::Result<()> {
6868

6969
#[cfg(test)]
7070
mod test {
71-
use crate::{run, run_with_commands, CliCommand};
71+
use crate::{run_with_commands, CliCommand, LOCAL_HOST};
7272
use clap::Parser;
73-
use spa_server::LOCAL_HOST;
7473
use std::env;
7574

7675
fn init_config() {
@@ -79,12 +78,14 @@ mod test {
7978
env::set_var("SPA_UPLOAD_PARALLEL", "4");
8079
}
8180

81+
#[ignore]
8282
#[tokio::test]
8383
async fn test_info() {
8484
init_config();
8585
run_with_commands(CliCommand::parse_from(&["test", "info"])).await.unwrap();
8686
}
8787

88+
#[ignore]
8889
#[tokio::test]
8990
async fn test_upload() {
9091
init_config();
@@ -98,6 +99,7 @@ mod test {
9899
println!("{:?}", ret);
99100
}
100101
}
102+
#[ignore]
101103
#[tokio::test]
102104
async fn test_release() {
103105
init_config();
@@ -108,6 +110,8 @@ mod test {
108110
])).await;
109111
result.unwrap();
110112
}
113+
114+
#[ignore]
111115
#[tokio::test]
112116
async fn test_delete() {
113117
init_config();
@@ -120,3 +124,5 @@ mod test {
120124
result.unwrap();
121125
}
122126
}
127+
#[cfg(test)]
128+
const LOCAL_HOST: &str = "local.fornetcode.com";

server/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spa-server"
3-
version = "2.2.2"
3+
version = "2.2.3"
44
edition = "2021"
55
authors = ["timzaak"]
66
license = "MIT"

server/src/config.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use anyhow::Context;
1+
use anyhow::{bail, Context};
22
use hocon::de::wrappers::Serde;
33
use serde::Deserialize;
44
use std::env;
55
use std::time::Duration;
6+
use tracing::warn;
67

78
const CONFIG_PATH: &str = "/config/config.conf";
89

@@ -29,9 +30,22 @@ impl Config {
2930
.load_file(&config_path)
3031
.with_context(|| format!("can not read config file: {config_path}"))?;
3132

32-
load_file
33+
let config = load_file
3334
.resolve::<Config>()
34-
.with_context(|| "parse config file error")
35+
.with_context(|| "parse config file error")?;
36+
if config.http.is_none() && config.https.is_none() {
37+
bail!("should set http or https server config")
38+
}
39+
if let Some(http_config) = &config.https {
40+
if http_config.acme.is_some() && http_config.ssl.is_some() {
41+
bail!("spa-server don't support ssl and acme config in the meantime");
42+
}
43+
if http_config.acme.is_some() && config.http.as_ref().filter(|v|v.port != 80).is_none() {
44+
warn!("acme needs http port:80 to signed https certificate");
45+
}
46+
}
47+
Ok(config)
48+
3549
}
3650
}
3751
#[derive(Deserialize, Debug, Clone, Eq, PartialEq)]
@@ -141,5 +155,5 @@ pub fn default_cron() -> String {
141155
String::from("0 0 3 * * *")
142156
}
143157
pub fn default_max_reserve() -> u32 {
144-
return 2;
158+
2
145159
}

server/src/domain_storage.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -821,13 +821,14 @@ mod test {
821821
// println!("{:?}", path.join("usr/lib/pam/").to_str());
822822
// }
823823

824+
#[ignore]
824825
#[test]
825826
fn test_domain_storage_get_domain_info() {
826827
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../test/config.test.conf");
827828
env::set_var("SPA_CONFIG", path.display().to_string());
828829
let mut config = Config::load().unwrap();
829830
config.file_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
830-
.join("../test/data")
831+
.join("../tests/web/data")
831832
.display()
832833
.to_string();
833834
let file_cache = FileCache::new(&config);
@@ -836,6 +837,8 @@ mod test {
836837

837838
println!("{:?}", result);
838839
}
840+
841+
#[ignore]
839842
#[test]
840843
fn test_file_read() {
841844
let mut file = OpenOptions::new()

server/src/lib.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::convert::Infallible;
3030
use std::sync::Arc;
3131
use std::time::Duration;
3232
use futures_util::TryFutureExt;
33-
use tracing::{error, warn};
33+
use tracing::error;
3434
use warp::Filter;
3535
use crate::tls::load_ssl_server_config;
3636

@@ -104,18 +104,10 @@ pub async fn reload_server(
104104
pub async fn run_server() -> anyhow::Result<()> {
105105
let config = Config::load()?;
106106
tracing::debug!("config load:{:?}", &config);
107+
run_server_with_config(config).await
108+
}
107109

108-
if config.http.is_none() && config.https.is_none() {
109-
panic!("should set http or https server config");
110-
}
111-
if let Some(http_config) = &config.https {
112-
if http_config.acme.is_some() && http_config.ssl.is_some() {
113-
panic!("spa-server don't support ssl and acme config in the meantime");
114-
}
115-
if http_config.acme.is_some() && config.http.as_ref().filter(|v|v.port != 80).is_none() {
116-
warn!("acme needs http port:80 to signed https certificate");
117-
}
118-
}
110+
pub async fn run_server_with_config(config:Config) -> anyhow::Result<()> {
119111
let cache = FileCache::new(&config);
120112
let domain_storage = Arc::new(DomainStorage::init(&config.file_dir, cache)?);
121113
let server = Server::new(config.clone(), domain_storage.clone());
@@ -164,8 +156,6 @@ pub async fn run_server() -> anyhow::Result<()> {
164156
panic!("admin server error: {error}")
165157
})
166158
);
167-
168-
169159
} else {
170160
tracing::info!("admin server disabled");
171161

@@ -192,9 +182,8 @@ pub async fn run_server() -> anyhow::Result<()> {
192182
}),
193183
);
194184
}
195-
196185
Ok(())
197186
}
198187

199-
//#[cfg(test)]
188+
#[cfg(test)]
200189
pub const LOCAL_HOST: &str = "local.fornetcode.com";

server/src/service.rs

-9
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,6 @@ pub fn resp(code: StatusCode, str: &'static str) -> Response<Body> {
132132
resp
133133
}
134134

135-
#[cfg(test)]
136-
mod test {
137-
#[test]
138-
fn test_r_split() {
139-
let z = "/_version/_api";
140-
println!("{:?}", "/_version/_api".rsplit_once(z));
141-
}
142-
}
143-
144135
// get version
145136
/*
146137
let uri = req.uri();

server/src/tls.rs

-7
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,3 @@ impl Accept for TlsAcceptor {
262262
}
263263
}
264264
}
265-
266-
#[cfg(test)]
267-
mod test {
268-
269-
#[test]
270-
fn test_acme() {}
271-
}

tests/tests/starter.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::time::Duration;
55
mod common;
66
use crate::common::*;
77
use common::run_server;
8-
use spa_server::LOCAL_HOST;
8+
9+
const LOCAL_HOST: &str = "local.fornetcode.com";
910

1011
#[tokio::test(flavor = "multi_thread", worker_threads = 3)]
1112
async fn start_server_and_client_upload_file() {

0 commit comments

Comments
 (0)