summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-12-07 18:51:01 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-12-07 18:51:01 +0100
commitfd4050427f687ea9d12828a0417f073ab1516dd6 (patch)
tree481f56ec0a58b4576851c75aeb7f5110de2b8aaa
parente145fe4ad9d2160ffe646ae81f831c4e7bbcc718 (diff)
parentc316c5895885fb0ce0a6627f00ded6bcc81cca7c (diff)
Merge branch 'github-actions'
-rw-r--r--.github/workflows/ci.yml61
-rw-r--r--src/cli.rs6
-rw-r--r--src/client.rs2
-rw-r--r--src/commands/profile.rs2
-rw-r--r--src/profile/mod.rs27
-rw-r--r--src/profile/state.rs12
6 files changed, 79 insertions, 31 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..efece1a
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,61 @@
+on: [push, pull_request]
+
+name: CI
+
+jobs:
+ check:
+ name: Check
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ rust:
+ - 1.57.0
+ - stable
+ - beta
+
+ steps:
+ - name: Install dependencies
+ run: sudo apt-get install -y openssl pkg-config zlib1g protobuf-compiler
+
+ - name: Checkout sources
+ uses: actions/checkout@v2
+
+ - name: Install toolchain
+ uses: actions-rs/toolchain@v1
+ with:
+ toolchain: ${{ matrix.rust }}
+ override: true
+
+ - name: Run cargo check
+ uses: actions-rs/cargo@v1
+ with:
+ command: check
+
+ test:
+ needs: [check]
+ name: Test Suite
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ rust:
+ - 1.54.0
+ - stable
+ - beta
+ steps:
+ - name: Install dependencies
+ run: sudo apt-get install -y openssl pkg-config zlib1g protobuf-compiler
+
+ - name: Checkout sources
+ uses: actions/checkout@v2
+
+ - name: Install toolchain
+ uses: actions-rs/toolchain@v1
+ with:
+ toolchain: ${{ matrix.rust }}
+ override: true
+
+ - name: Run cargo test
+ uses: actions-rs/cargo@v1
+ with:
+ command: test
+ args: --all --all-features
diff --git a/src/cli.rs b/src/cli.rs
index 3041e33..8e912e0 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -20,7 +20,7 @@ pub fn app<'a>() -> App<'a> {
.version(crate_version!())
.about("Create profile")
- .arg(Arg::with_name("name")
+ .arg(Arg::new("name")
.long("name")
.required(true)
.takes_value(true)
@@ -34,7 +34,7 @@ pub fn app<'a>() -> App<'a> {
.version(crate_version!())
.about("Just serve the profile")
- .arg(Arg::with_name("name")
+ .arg(Arg::new("name")
.long("name")
.required(true)
.takes_value(true)
@@ -42,7 +42,7 @@ pub fn app<'a>() -> App<'a> {
.about("Name of the profile")
)
- .arg(Arg::with_name("connect")
+ .arg(Arg::new("connect")
.long("connect")
.required(false)
.takes_value(true)
diff --git a/src/client.rs b/src/client.rs
index 4e50a8e..bb280a5 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -1,8 +1,6 @@
use std::convert::TryFrom;
-use anyhow::Context;
use anyhow::Result;
-use futures::TryStreamExt;
use ipfs::Cid;
use crate::config::Config;
diff --git a/src/commands/profile.rs b/src/commands/profile.rs
index 4da70f1..853984f 100644
--- a/src/commands/profile.rs
+++ b/src/commands/profile.rs
@@ -44,7 +44,7 @@ async fn profile_serve(matches: &ArgMatches) -> Result<()> {
log::info!("Loading '{}' from {}", name, state_dir.display());
let profile = Profile::load(Config::default(), &name).await?;
log::info!("Profile loaded");
- log::info!("Profile HEAD = {}", profile.head());
+ log::info!("Profile HEAD = {:?}", profile.head());
if let Some(connect_to) = connect_peer {
log::info!("Connecting to {:?}", connect_to);
diff --git a/src/profile/mod.rs b/src/profile/mod.rs
index 8849e34..56b4ac9 100644
--- a/src/profile/mod.rs
+++ b/src/profile/mod.rs
@@ -24,7 +24,7 @@ impl Profile {
let keypair = ipfs::Keypair::generate_ed25519();
let options = ipfs::IpfsOptions {
- ipfs_path: Self::ipfs_path(state_dir, name).await?,
+ ipfs_path: Self::ipfs_path(state_dir).await?,
keypair,
bootstrap,
mdns,
@@ -41,6 +41,7 @@ impl Profile {
Self::new(ipfs, config, name.to_string(), keypair).await
}
+ #[cfg(test)]
async fn new_inmemory(config: Config, name: &str) -> Result<Self> {
let mut opts = ipfs::IpfsOptions::inmemory_with_generated_keys();
opts.mdns = true;
@@ -52,25 +53,19 @@ impl Profile {
async fn new(ipfs: IpfsClient, config: Config, profile_name: String, keypair: libp2p::identity::Keypair) -> Result<Self> {
let client = Client::new(ipfs, config);
- let profile_head = Self::post_hello_world(&client, &profile_name).await?;
- let state = ProfileState::new(profile_head, profile_name, keypair);
+ let state = ProfileState::new(profile_name, keypair);
Ok(Profile { state, client })
}
- pub fn head(&self) -> &cid::Cid {
- self.state.profile_head()
+ pub fn head(&self) -> Option<&cid::Cid> {
+ self.state.profile_head().as_ref()
}
pub async fn connect(&self, peer: ipfs::MultiaddrWithPeerId) -> Result<()> {
self.client.connect(peer).await
}
- async fn post_hello_world(client: &Client, name: &str) -> Result<cid::Cid> {
- let text = format!("Hello world, I am {}", name);
- client.post_text_node(vec![], text).await
- }
-
- async fn ipfs_path(state_dir: &StateDir, name: &str) -> Result<PathBuf> {
+ async fn ipfs_path(state_dir: &StateDir) -> Result<PathBuf> {
let path = state_dir.ipfs();
tokio::fs::create_dir_all(&path).await?;
Ok(path)
@@ -129,7 +124,7 @@ impl Profile {
log::debug!("Configuring IPFS backend");
let options = ipfs::IpfsOptions {
- ipfs_path: Self::ipfs_path(&state_dir_path, name).await?,
+ ipfs_path: Self::ipfs_path(&state_dir_path).await?,
keypair,
bootstrap,
mdns,
@@ -162,9 +157,7 @@ impl Profile {
mod tests {
use super::*;
use std::convert::TryFrom;
- use crate::client::Client;
use crate::config::Config;
- use crate::ipfs_client::IpfsClient;
#[tokio::test]
async fn test_create_profile() {
@@ -181,11 +174,7 @@ mod tests {
let profile = Profile::new_inmemory(Config::default(), "test-create-profile-and-helloworld").await;
assert!(profile.is_ok());
let profile = profile.unwrap();
- let head = profile.head();
- let exp_cid = cid::Cid::try_from("bafyreie4haukbqj7u6vogjfvaxbwg73b7bzi7nqxbnkvv77dvwcqg5wtpe").unwrap();
- assert_eq!(*head, exp_cid, "{} != {}", *head, exp_cid);
- let exit = profile.exit().await;
- assert!(exit.is_ok(), "Not cleanly exited: {:?}", exit);
+ assert!(profile.head().is_none());
}
}
diff --git a/src/profile/state.rs b/src/profile/state.rs
index a84ff23..4075b52 100644
--- a/src/profile/state.rs
+++ b/src/profile/state.rs
@@ -32,7 +32,7 @@ impl From<PathBuf> for StateDir {
#[derive(getset::Getters)]
pub struct ProfileState {
#[getset(get = "pub")]
- profile_head: cid::Cid,
+ profile_head: Option<cid::Cid>,
#[getset(get = "pub")]
profile_name: String,
@@ -42,9 +42,9 @@ pub struct ProfileState {
}
impl ProfileState {
- pub(super) fn new(profile_head: cid::Cid, profile_name: String, keypair: libp2p::identity::Keypair) -> Self {
+ pub(super) fn new(profile_name: String, keypair: libp2p::identity::Keypair) -> Self {
Self {
- profile_head,
+ profile_head: None,
profile_name,
keypair
}
@@ -59,7 +59,7 @@ impl std::fmt::Debug for ProfileState {
#[derive(Debug, serde::Serialize, serde::Deserialize, getset::Getters)]
pub(super) struct ProfileStateSaveable {
- profile_head: Vec<u8>,
+ profile_head: Option<Vec<u8>>,
profile_name: String,
keypair: Vec<u8>,
}
@@ -67,7 +67,7 @@ pub(super) struct ProfileStateSaveable {
impl ProfileStateSaveable {
pub(super) fn new(s: &ProfileState) -> Result<Self> {
Ok(Self {
- profile_head: s.profile_head.to_bytes(),
+ profile_head: s.profile_head.clone().map(|v| v.to_bytes()),
profile_name: s.profile_name.clone(),
keypair: match s.keypair {
libp2p::identity::Keypair::Ed25519(ref kp) => Vec::from(kp.encode()),
@@ -116,7 +116,7 @@ impl TryInto<ProfileState> for ProfileStateSaveable {
fn try_into(mut self) -> Result<ProfileState> {
Ok(ProfileState {
- profile_head: cid::Cid::try_from(self.profile_head)?,
+ profile_head: self.profile_head.map(|h| cid::Cid::try_from(h)).transpose()?,
profile_name: self.profile_name,
keypair: {
let kp = libp2p::identity::ed25519::Keypair::decode(&mut self.keypair)?;