Skip to content

Commit

Permalink
Fix: Adjusts tests to make them compatible with inmemory and github u…
Browse files Browse the repository at this point in the history
…sing ceramic docker
  • Loading branch information
dbcfd committed May 9, 2023
1 parent 5f6eebc commit 872e7a5
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github
src
target
7 changes: 7 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,12 @@ jobs:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Start Ceramic
run: docker compose -f it/docker-compose.yml up -d
- name: Wait for Ceramic
run: ./it/wait_for_ceramic.sh
- name: Run tests
run: cargo test --verbose

env:
DID_PRIVATE_KEY: ${{ secrets.DID_PRIVATE_KEY }}
36 changes: 36 additions & 0 deletions it/data/daemon_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"anchor": {},
"http-api": {
"hostname": "127.0.0.1",
"port": 7071,
"admin-dids": [
"did:key:z6MkeqCTPhHPVg3HaAAtsR7vZ6FXkAHPXEbTJs7Y4CQABV9Z"
]
},
"ipfs": {
"mode": "bundled"
},
"logger": {
"log-directory": "/root/.ceramic/log",
"log-level": 2,
"log-to-files": true
},
"metrics": {
"metrics-exporter-enabled": false
},
"network": {
"name": "inmemory"
},
"node": {
"gateway": false
},
"state-store": {
"mode": "file",
"local-directory": "/root/.ceramic/statestore"
},
"indexing": {
"db": "/root/.ceramic/ceramic.db",
"allow-queries-before-historical-sync": false,
"enable-historical-sync": false
}
}
15 changes: 15 additions & 0 deletions it/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Docker compose to bring up ceramic
version: '3'
services:
ceramic-service:
image: ceramicnetwork/js-ceramic
volumes:
- ./it/data:/root/.ceramic
ports:
- 7071:7071
networks:
- ceramic-testing-network

# network can be any name but make sure it use a same name.
networks:
ceramic-testing-network:
5 changes: 5 additions & 0 deletions it/wait_for_ceramic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

while [ $(curl -s -o /dev/null -I -w "%{http_code}" "http://127.0.0.1:7071/api/v0/node/healthcheck") -ne "200" ]; do
sleep 1
done
63 changes: 37 additions & 26 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use ceramic_event::{
Base64String, Jws, MultiBase32String, MultiBase36String, StreamId, StreamIdType,
};
use ceramic_event::{Base64String, Jws, MultiBase32String, MultiBase36String, StreamId, StreamIdType};
use serde::{Deserialize, Serialize};

#[derive(Serialize)]
Expand Down Expand Up @@ -43,28 +41,6 @@ pub struct UpdateRequest {
pub stream_id: MultiBase36String,
}

#[derive(Deserialize)]
pub struct PostResponse {
error: Option<String>,
#[serde(rename = "streamId")]
stream_id: Option<StreamId>,
}

impl PostResponse {
pub fn resolve(self, context: &str) -> anyhow::Result<StreamId> {
if let Some(stream_id) = self.stream_id {
Ok(stream_id)
} else {
let post = if let Some(err) = self.error {
format!(": {}", err)
} else {
": No additional information provided by ceramic".to_string()
};
anyhow::bail!(format!("{}{}", context, post))
}
}
}

#[derive(Deserialize)]
pub struct StateLog {
pub cid: MultiBase36String,
Expand All @@ -83,9 +59,44 @@ pub struct StreamState {
pub metadata: Metadata,
}

#[derive(Deserialize)]
pub struct PostResponse {
#[serde(rename = "streamId")]
pub stream_id: StreamId,
pub state: Option<StreamState>,
}

#[derive(Deserialize)]
#[serde(untagged)]
pub enum PostResponseOrError {
Error {
error: String,
},
Ok(PostResponse),
}

impl PostResponseOrError {
pub fn resolve(self, context: &str) -> anyhow::Result<PostResponse> {
match self {
Self::Error { error } => {
anyhow::bail!(format!("{}: {}", context, error))
}
Self::Ok(resp) => {
Ok(resp)
}
}
}
}

#[derive(Deserialize)]
pub struct Commit {
pub cid: MultiBase36String,
pub value: serde_json::Value,
}

#[derive(Deserialize)]
pub struct GetResponse {
#[serde(rename = "streamId")]
pub stream_id: StreamId,
pub state: StreamState,
pub commits: Vec<Commit>,
}
Loading

0 comments on commit 872e7a5

Please sign in to comment.