chore: fix tests in ci

This commit is contained in:
nazeh
2024-07-30 13:46:04 +03:00
parent 2366e066cc
commit d8d3a43abd
6 changed files with 45 additions and 40 deletions

View File

@@ -36,6 +36,7 @@ jobs:
restore-keys: |
${{ runner.os }}-cargo-index-
- name: Cache cargo build
id: cargo-build-cache
uses: actions/cache@v2
with:
path: target
@@ -54,20 +55,21 @@ jobs:
cargo install cargo-nextest
fi
# - name: Check no default features
# run: cargo check --no-default-features
- name: Check no default features
run: cargo check --no-default-features
# - name: Check formatting
# run: cargo fmt -- --check
- name: Check formatting
run: cargo fmt -- --check
# - name: Lint with Clippy
# run: cargo clippy --workspace --all-features --bins --tests
- name: Lint with Clippy
run: cargo clippy --workspace --all-features --bins --tests
# - name: Build
# run: cargo build --release --workspace --all-features --verbose
- name: Build
if: steps.cargo-build-cache.outputs.cache-hit != 'true'
run: cargo build --release --workspace --all-features --verbose
- name: Run tests with Nextest
run: cargo nextest run homeserver_in_tokio
run: cargo nextest run --all-features --workspace --verbose
# - name: Run docs
# run: cargo doc --workspace --all-features --no-deps --document-private-items --verbose
- name: Run docs
run: cargo doc --workspace --all-features --no-deps --document-private-items --verbose

View File

@@ -16,15 +16,14 @@ const DEFAULT_STORAGE_DIR: &str = "pubky";
Clone,
)]
pub struct Config {
pub port: Option<u16>,
pub bootstrap: Option<Vec<String>>,
pub domain: String,
port: Option<u16>,
bootstrap: Option<Vec<String>>,
domain: String,
/// Path to the storage directory
///
/// Defaults to a directory in the OS data directory
pub storage: Option<PathBuf>,
pub keypair: Keypair,
pub request_timeout: Option<Duration>,
storage: Option<PathBuf>,
keypair: Keypair,
}
impl Config {
@@ -37,6 +36,26 @@ impl Config {
// Ok(config)
// }
/// Testnet configurations
pub fn testnet() -> Self {
let testnet = pkarr::mainline::Testnet::new(10);
let bootstrap = Some(testnet.bootstrap.to_owned());
let storage = Some(
std::env::temp_dir()
.join(Timestamp::now().to_string())
.join(DEFAULT_STORAGE_DIR),
);
Self {
bootstrap,
storage,
port: Some(15411),
keypair: Keypair::from_secret_key(&[0_u8; 32]),
..Default::default()
}
}
/// Test configurations
pub fn test(testnet: &pkarr::mainline::Testnet) -> Self {
let bootstrap = Some(testnet.bootstrap.to_owned());
@@ -49,7 +68,6 @@ impl Config {
Self {
bootstrap,
storage,
request_timeout: Some(Duration::from_millis(10)),
..Default::default()
}
}
@@ -93,7 +111,6 @@ impl Default for Config {
domain: "localhost".to_string(),
storage: None,
keypair: Keypair::random(),
request_timeout: None,
}
}
}

View File

@@ -1,5 +1,4 @@
use anyhow::Result;
use pkarr::{mainline::Testnet, Keypair};
use pubky_homeserver::{config::Config, Homeserver};
use clap::Parser;
@@ -24,18 +23,12 @@ async fn main() -> Result<()> {
)
.init();
let server = if args.testnet {
let testnet = Testnet::new(10);
Homeserver::start(Config {
port: Some(15411),
keypair: Keypair::from_secret_key(&[0_u8; 32]),
..Config::test(&testnet)
})
.await?
let server = Homeserver::start(if args.testnet {
Config::testnet()
} else {
Homeserver::start(Default::default()).await?
};
Default::default()
})
.await?;
server.run_until_done().await?;

View File

@@ -39,7 +39,6 @@ impl Homeserver {
let pkarr_client = PkarrClient::new(Settings {
dht: DhtSettings {
bootstrap: config.bootstsrap(),
request_timeout: config.request_timeout,
..Default::default()
},
..Default::default()

View File

@@ -44,7 +44,7 @@ impl PubkyClient {
.unwrap(),
pkarr: PkarrClient::new(Settings {
dht: DhtSettings {
request_timeout: Some(Duration::from_millis(10)),
request_timeout: Some(Duration::from_millis(100)),
bootstrap: Some(testnet.bootstrap.to_owned()),
..DhtSettings::default()
},

View File

@@ -139,17 +139,11 @@ mod tests {
use pkarr::{
dns::{rdata::SVCB, Packet},
mainline::{dht::DhtSettings, Testnet},
mainline::{dht::DhtSettings, Dht, Testnet},
Keypair, PkarrClient, Settings, SignedPacket,
};
use pubky_homeserver::Homeserver;
#[tokio::test]
fn homeserver_in_tokio() {
let testnet = Testnet::new(10);
let server = Homeserver::start_test(&testnet).await.unwrap();
}
#[tokio::test]
async fn resolve_homeserver() {
let testnet = Testnet::new(10);