Skip to content

Commit

Permalink
chore: fix tests in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuhvi committed Jul 30, 2024
1 parent 2366e06 commit 85c340d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 38 deletions.
21 changes: 11 additions & 10 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,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
# 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
33 changes: 25 additions & 8 deletions pubky-homeserver/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
Expand All @@ -49,7 +68,6 @@ impl Config {
Self {
bootstrap,
storage,
request_timeout: Some(Duration::from_millis(10)),
..Default::default()
}
}
Expand Down Expand Up @@ -93,7 +111,6 @@ impl Default for Config {
domain: "localhost".to_string(),
storage: None,
keypair: Keypair::random(),
request_timeout: None,
}
}
}
Expand Down
17 changes: 5 additions & 12 deletions pubky-homeserver/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Result;
use pkarr::{mainline::Testnet, Keypair};
use pubky_homeserver::{config::Config, Homeserver};

use clap::Parser;
Expand All @@ -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?;

Expand Down
1 change: 0 additions & 1 deletion pubky-homeserver/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 1 addition & 7 deletions pubky/src/shared/pkarr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 85c340d

Please sign in to comment.