Skip to content

Commit

Permalink
feat: read ceramic urls envar
Browse files Browse the repository at this point in the history
  • Loading branch information
smrz2001 committed Aug 18, 2023
1 parent a745422 commit 503092c
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish Docker Image

on:
push:
branches: [ "main" ]
branches: [ "main", "feat/initial" ]

jobs:
publish:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
# default: "v0-rust"
prefix-key: "v2"
- name: Build
run: make release
run: make build
- name: Check fmt
run: make check-fmt
- name: Check clippy
Expand Down
180 changes: 180 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
dotenvy = "0.15.7"
rstest = "0.18.2"
tracing = "0.1"
tracing-test = "0.2"
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ RUN --mount=type=cache,target=/home/builder/.cargo,uid=$UID,gid=$GID \

FROM ubuntu:latest as tester

COPY --from=builder /home/builder/rust-ceramic-migration-tests/env/.env /usr/bin/.env
COPY --from=builder /home/builder/rust-ceramic-migration-tests/rust-ceramic-migration-tests /usr/bin

ENV RUST_BACKTRACE=1
ENV CERAMIC_URLS=""
ENV ENV_PATH=".env"

ENTRYPOINT ["/usr/bin/rust-ceramic-migration-tests"]
5 changes: 5 additions & 0 deletions LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
19 changes: 19 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
.PHONY: all
all: check-fmt check-clippy test

.PHONY: build
build: release

.PHONY: release
release:
$(eval BIN=$(shell sh -c "RUSTFLAGS='-D warnings' cargo test --no-run --locked --release -q --message-format=json | jq -r 'select(.executable != null) | .executable'"))
Expand All @@ -19,10 +22,7 @@ debug:

.PHONY: test
test:
# Test with default features
cargo test --locked
# Test with all features
cargo test --locked --all-features
cargo test --locked --all-features -- --nocapture

.PHONY: check-fmt
check-fmt:
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Rust Ceramic Migration Tests

Tests needed to verify the migration from [Kubo](https://github.com/ceramicnetwork/go-ipfs-daemon) to
[rust-ceramic](https://github.com/3box/rust-ceramic) when used with
[Ceramic](https://github.com/ceramicnetwork/js-ceramic) nodes.

## Contributing

We are happy to accept small and large contributions, feel free to make a suggestion or submit a pull request.

Use the provided `Makefile` for basic actions to ensure your changes are ready for CI.

$ make build
$ make check-clippy
$ make check-fmt

Using the makefile is not necessary during your development cycle, feel free to use the relevant cargo commands
directly. However, running `make` before publishing a PR will provide a good signal if your PR will pass CI.

## License

Fully open source and dual-licensed under MIT and Apache 2.
1 change: 1 addition & 0 deletions env/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CERAMIC_URLS=https://ceramic-private-dev.3boxlabs.com,https://ceramic-dev.3boxlabs.com
37 changes: 31 additions & 6 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
#[cfg(test)]
pub mod tests {
use std::env;
use std::path::Path;

use rstest::{fixture, rstest};
use tracing_test::traced_test;

#[test]
const CERAMIC_URLS: &str = "CERAMIC_URLS";
const DEFAULT_ENV_PATH: &str = "env/.env";
const ENV_PATH: &str = "ENV_PATH";

#[fixture]
#[once]
fn initialize() {
dotenvy::from_path(Path::new(
env::var(ENV_PATH)
.unwrap_or(DEFAULT_ENV_PATH.to_owned())
.as_str(),
))
.expect("Could not find .env file");
}

fn print_ceramic_urls() {
println!("{:?}", env::var(CERAMIC_URLS).unwrap_or_default());
}

#[rstest]
#[traced_test]
fn test_1() {
println!("Hello world!");
fn test_1(_initialize: ()) {
println!("Hello Ceramic!");
print_ceramic_urls();
}

#[test]
#[rstest]
#[traced_test]
fn test_2() {
println!("Goodbye world!");
fn test_2(_initialize: ()) {
println!("Goodbye Ceramic!");
print_ceramic_urls();
}
}

0 comments on commit 503092c

Please sign in to comment.