mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-12 10:55:32 +00:00
chore: move test-sdk examples from marine repo (#95)
* move related examples * update Cargo.lock * update test macro invocations * update naming + add CI step * add marine download CI step * remove aggressive cargo update * fix ci
This commit is contained in:
parent
71b0645338
commit
0bf0489ed2
23
.github/workflows/tests.yml
vendored
23
.github/workflows/tests.yml
vendored
@ -51,12 +51,32 @@ jobs:
|
||||
- name: Setup Rust toolchain
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
|
||||
- name: Download marine artifact
|
||||
id: marine
|
||||
uses: actions/download-artifact@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
name: marine
|
||||
path: ~/.local/bin
|
||||
|
||||
- name: Make marine executable
|
||||
if: steps.marine.outcome == 'success'
|
||||
run: chmod +x ~/.local/bin/marine
|
||||
|
||||
- name: Setup marine
|
||||
if: steps.marine.outcome == 'failure'
|
||||
uses: fluencelabs/setup-marine@v1
|
||||
|
||||
- name: Set dependencies
|
||||
if: inputs.cargo-dependencies != ''
|
||||
uses: fluencelabs/github-actions/cargo-set-dependency@main
|
||||
with:
|
||||
dependencies: ${{ inputs.cargo-dependencies }}
|
||||
|
||||
- name: Build examples
|
||||
working-directory: examples
|
||||
run: build.sh
|
||||
|
||||
- name: Run cargo check
|
||||
run: cargo check -v --all-features
|
||||
|
||||
@ -66,6 +86,9 @@ jobs:
|
||||
- name: Run cargo clippy
|
||||
run: cargo clippy -Z unstable-options --all
|
||||
|
||||
- name: Test examples
|
||||
run: cargo test -p single-service-example -p multi-service-example -p build-rs-example
|
||||
|
||||
- name: Run rustfmt
|
||||
uses: actions-rust-lang/rustfmt@v1
|
||||
|
||||
|
1058
Cargo.lock
generated
1058
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -34,4 +34,7 @@ members = [
|
||||
"crates/marine-test-macro",
|
||||
"crates/marine-test-macro-impl",
|
||||
"crates/marine-build-rs-generator",
|
||||
"examples/build_rs",
|
||||
"examples/single-service",
|
||||
"examples/multi-service",
|
||||
]
|
||||
|
13
examples/build.sh
Executable file
13
examples/build.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
for dir in ./*; do
|
||||
# skip non-directory entries
|
||||
[ -d "$dir" ] || continue
|
||||
|
||||
# skip if there's no build.sh in the directory
|
||||
[ -e "$dir/build.sh" ] || continue
|
||||
|
||||
(cd "$dir"; ./build.sh)
|
||||
done
|
21
examples/build_rs/Cargo.toml
Normal file
21
examples/build_rs/Cargo.toml
Normal file
@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "build-rs-example"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
description = "The greeting module for the Fluence network"
|
||||
repository = "https://github.com/fluencelabs/marine/tree/master/examples/build_rs"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "build_rs_test"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
marine-rs-sdk = "0.8.1"
|
||||
|
||||
[dev-dependencies]
|
||||
marine-rs-sdk-test = { path = "../.." }
|
||||
|
||||
[build-dependencies]
|
||||
marine-rs-sdk-test = { path = "../.." }
|
6
examples/build_rs/Config.toml
Normal file
6
examples/build_rs/Config.toml
Normal file
@ -0,0 +1,6 @@
|
||||
modules_dir = "artifacts/"
|
||||
|
||||
[[module]]
|
||||
name = "build_rs_test"
|
||||
max_heap_size = "10 KiB"
|
||||
logger_enabled = false
|
18
examples/build_rs/build.rs
Normal file
18
examples/build_rs/build.rs
Normal file
@ -0,0 +1,18 @@
|
||||
use marine_rs_sdk_test::generate_marine_test_env;
|
||||
use marine_rs_sdk_test::ServiceDescription;
|
||||
fn main() {
|
||||
let services = vec![(
|
||||
"greeting".to_string(),
|
||||
ServiceDescription {
|
||||
config_path: "Config.toml".to_string(),
|
||||
modules_dir: None,
|
||||
},
|
||||
)];
|
||||
|
||||
let target = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
|
||||
if target != "wasm32" {
|
||||
generate_marine_test_env(services, "marine_test_env.rs", file!());
|
||||
}
|
||||
|
||||
println!("cargo:rerun-if-changed=src/main.rs");
|
||||
}
|
9
examples/build_rs/build.sh
Executable file
9
examples/build_rs/build.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This script builds all subprojects and puts all created Wasm modules in one dir
|
||||
marine build --release
|
||||
|
||||
rm artifacts/* || true
|
||||
mkdir -p artifacts
|
||||
|
||||
cp ../../target/wasm32-wasi/release/build_rs_test.wasm artifacts/
|
38
examples/build_rs/src/main.rs
Normal file
38
examples/build_rs/src/main.rs
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2021 Fluence Labs Limited
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
use marine_rs_sdk::marine;
|
||||
use marine_rs_sdk::module_manifest;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[marine]
|
||||
pub fn greeting(name: String) -> String {
|
||||
format!("Hi, {}", name)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod built_tests {
|
||||
marine_rs_sdk_test::include_test_env!("/marine_test_env.rs");
|
||||
#[test]
|
||||
fn non_empty_string() {
|
||||
let mut greeting = marine_test_env::greeting::ServiceInterface::new();
|
||||
let actual = greeting.greeting("name".to_string());
|
||||
assert_eq!(actual, "Hi, name");
|
||||
}
|
||||
}
|
11
examples/multi-service/Cargo.toml
Normal file
11
examples/multi-service/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "multi-service-example"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dev-dependencies]
|
||||
marine-rs-sdk-test = { path = "../.." }
|
13
examples/multi-service/consumer/Cargo.toml
Normal file
13
examples/multi-service/consumer/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "consumer"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "consumer"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
marine-rs-sdk = "0.8.1"
|
6
examples/multi-service/consumer/Config.toml
Normal file
6
examples/multi-service/consumer/Config.toml
Normal file
@ -0,0 +1,6 @@
|
||||
modules_dir = "artifacts/"
|
||||
|
||||
[[module]]
|
||||
name = "consumer"
|
||||
max_heap_size = "10 KiB"
|
||||
logger_enabled = false
|
9
examples/multi-service/consumer/build.sh
Executable file
9
examples/multi-service/consumer/build.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This script builds all subprojects and puts all created Wasm modules in one dir
|
||||
marine build --release
|
||||
|
||||
rm artifacts/* || true
|
||||
mkdir -p artifacts
|
||||
|
||||
cp target/wasm32-wasi/release/consumer.wasm artifacts/
|
16
examples/multi-service/consumer/src/main.rs
Normal file
16
examples/multi-service/consumer/src/main.rs
Normal file
@ -0,0 +1,16 @@
|
||||
use marine_rs_sdk::marine;
|
||||
use marine_rs_sdk::module_manifest;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[marine]
|
||||
pub struct Data {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[marine]
|
||||
pub fn consume(data: Data) -> String {
|
||||
data.name
|
||||
}
|
13
examples/multi-service/producer/Cargo.toml
Normal file
13
examples/multi-service/producer/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "producer"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "producer"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
marine-rs-sdk = "0.8.1"
|
6
examples/multi-service/producer/Config.toml
Normal file
6
examples/multi-service/producer/Config.toml
Normal file
@ -0,0 +1,6 @@
|
||||
modules_dir = "artifacts/"
|
||||
|
||||
[[module]]
|
||||
name = "producer"
|
||||
max_heap_size = "10 KiB"
|
||||
logger_enabled = false
|
9
examples/multi-service/producer/build.sh
Executable file
9
examples/multi-service/producer/build.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This script builds all subprojects and puts all created Wasm modules in one dir
|
||||
marine build --release
|
||||
|
||||
rm artifacts/* || true
|
||||
mkdir -p artifacts
|
||||
|
||||
cp target/wasm32-wasi/release/producer.wasm artifacts/
|
24
examples/multi-service/producer/src/main.rs
Normal file
24
examples/multi-service/producer/src/main.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use marine_rs_sdk::marine;
|
||||
use marine_rs_sdk::module_manifest;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[marine]
|
||||
pub struct Data {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[marine]
|
||||
pub struct Input {
|
||||
pub first_name: String,
|
||||
pub last_name: String,
|
||||
}
|
||||
|
||||
#[marine]
|
||||
pub fn produce(data: Input) -> Data {
|
||||
Data {
|
||||
name: format!("{} {}", data.first_name, data.last_name),
|
||||
}
|
||||
}
|
47
examples/multi-service/src/main.rs
Normal file
47
examples/multi-service/src/main.rs
Normal file
@ -0,0 +1,47 @@
|
||||
fn main() {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use marine_rs_sdk_test::marine_test;
|
||||
#[marine_test(
|
||||
producer(config_path = "../producer/Config.toml"),
|
||||
consumer(config_path = "../consumer/Config.toml")
|
||||
)]
|
||||
fn test() {
|
||||
let mut producer = marine_test_env::producer::ServiceInterface::new();
|
||||
let mut consumer = marine_test_env::consumer::ServiceInterface::new();
|
||||
let input = marine_test_env::producer::Input {
|
||||
first_name: String::from("John"),
|
||||
last_name: String::from("Doe"),
|
||||
};
|
||||
let data = producer.produce(input);
|
||||
let result = consumer.consume(data);
|
||||
assert_eq!(result, "John Doe")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[marine_rs_sdk_test::marine_test(
|
||||
producer(
|
||||
config_path = "../producer/Config.toml",
|
||||
modules_dir = "../producer/artifacts"
|
||||
),
|
||||
consumer(
|
||||
config_path = "../consumer/Config.toml",
|
||||
modules_dir = "../consumer/artifacts"
|
||||
)
|
||||
)]
|
||||
mod tests_on_mod {
|
||||
#[test]
|
||||
fn test() {
|
||||
let mut producer = marine_test_env::producer::ServiceInterface::new();
|
||||
let mut consumer = marine_test_env::consumer::ServiceInterface::new();
|
||||
let input = marine_test_env::producer::Input {
|
||||
first_name: String::from("John"),
|
||||
last_name: String::from("Doe"),
|
||||
};
|
||||
let data = producer.produce(input);
|
||||
let result = consumer.consume(data);
|
||||
assert_eq!(result, "John Doe")
|
||||
}
|
||||
}
|
18
examples/single-service/Cargo.toml
Normal file
18
examples/single-service/Cargo.toml
Normal file
@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "single-service-example"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
description = "The greeting module for the Fluence network"
|
||||
repository = "https://github.com/fluencelabs/marine/tree/master/examples/greeting"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "greeting"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
marine-rs-sdk = "0.8.1"
|
||||
|
||||
[dev-dependencies]
|
||||
marine-rs-sdk-test = { path = "../.." }
|
6
examples/single-service/Config.toml
Normal file
6
examples/single-service/Config.toml
Normal file
@ -0,0 +1,6 @@
|
||||
modules_dir = "artifacts/"
|
||||
|
||||
[[module]]
|
||||
name = "greeting"
|
||||
max_heap_size = "10 KiB"
|
||||
logger_enabled = false
|
9
examples/single-service/build.sh
Executable file
9
examples/single-service/build.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This script builds all subprojects and puts all created Wasm modules in one dir
|
||||
marine build --release
|
||||
|
||||
rm artifacts/* || true
|
||||
mkdir -p artifacts
|
||||
|
||||
cp ../../target/wasm32-wasi/release/greeting.wasm artifacts/
|
44
examples/single-service/src/main.rs
Normal file
44
examples/single-service/src/main.rs
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2020 Fluence Labs Limited
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
use marine_rs_sdk::marine;
|
||||
use marine_rs_sdk::module_manifest;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[marine]
|
||||
pub fn greeting(name: String) -> String {
|
||||
format!("Hi, {}", name)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use marine_rs_sdk_test::marine_test;
|
||||
|
||||
#[marine_test(config_path = "../Config.toml")]
|
||||
fn empty_string(greeting: marine_test_env::greeting::ModuleInterface) {
|
||||
let actual = greeting.greeting(String::new());
|
||||
assert_eq!(actual, "Hi, ");
|
||||
}
|
||||
|
||||
#[marine_test(config_path = "../Config.toml")]
|
||||
fn non_empty_string(greeting: marine_test_env::greeting::ModuleInterface) {
|
||||
let actual = greeting.greeting("name".to_string());
|
||||
assert_eq!(actual, "Hi, name");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user