change: rename core
crate to service
in examples (#1662)
* change: rename `core` crate to `service` in examples * fix(jsonrpsee-example): broken dependency
This commit is contained in:
parent
59e3ba8095
commit
0b15f4f5e2
@ -6,7 +6,7 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[workspace]
|
||||
members = [".", "api", "core", "entity", "migration"]
|
||||
members = [".", "api", "service", "entity", "migration"]
|
||||
|
||||
[dependencies]
|
||||
actix3-example-api = { path = "api" }
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
|
||||
|
||||
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-mysql",` line)
|
||||
1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-mysql",` line)
|
||||
|
||||
1. Execute `cargo run` to start the server
|
||||
|
||||
@ -19,9 +19,9 @@ cargo install systemfd
|
||||
systemfd --no-pid -s http::8000 -- cargo watch -x run
|
||||
```
|
||||
|
||||
Run mock test on the core logic crate:
|
||||
Run mock test on the service logic crate:
|
||||
|
||||
```bash
|
||||
cd core
|
||||
cd service
|
||||
cargo test --features mock
|
||||
```
|
||||
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
actix3-example-core = { path = "../core" }
|
||||
actix3-example-service = { path = "../service" }
|
||||
actix-http = "2"
|
||||
actix-web = "3"
|
||||
actix-flash = "0.2"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use actix3_example_core::{
|
||||
use actix3_example_service::{
|
||||
sea_orm::{Database, DatabaseConnection},
|
||||
Mutation, Query,
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "actix-example-core"
|
||||
name = "actix3-example-service"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
@ -1,7 +1,7 @@
|
||||
mod prepare;
|
||||
|
||||
use actix3_example_service::{Mutation, Query};
|
||||
use entity::post;
|
||||
use jsonrpsee_example_core::{Mutation, Query};
|
||||
use prepare::prepare_mock_db;
|
||||
|
||||
#[tokio::test]
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[workspace]
|
||||
members = [".", "api", "core", "entity", "migration"]
|
||||
members = [".", "api", "service", "entity", "migration"]
|
||||
|
||||
[dependencies]
|
||||
actix-example-api = { path = "api" }
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
|
||||
|
||||
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-mysql",` line)
|
||||
1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-mysql",` line)
|
||||
|
||||
1. Execute `cargo run` to start the server
|
||||
|
||||
@ -17,9 +17,9 @@ cargo install systemfd cargo-watch
|
||||
systemfd --no-pid -s http::8000 -- cargo watch -x run
|
||||
```
|
||||
|
||||
Run mock test on the core logic crate:
|
||||
Run mock test on the service logic crate:
|
||||
|
||||
```bash
|
||||
cd core
|
||||
cd service
|
||||
cargo test --features mock
|
||||
```
|
||||
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
actix-example-core = { path = "../core" }
|
||||
actix-example-service = { path = "../service" }
|
||||
actix-files = "0.6"
|
||||
actix-http = "3"
|
||||
actix-rt = "2.7"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use actix_example_core::{
|
||||
use actix_example_service::{
|
||||
sea_orm::{Database, DatabaseConnection},
|
||||
Mutation, Query,
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "actix3-example-core"
|
||||
name = "actix-example-service"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
@ -1,7 +1,7 @@
|
||||
mod prepare;
|
||||
|
||||
use actix_example_service::{Mutation, Query};
|
||||
use entity::post;
|
||||
use poem_example_core::{Mutation, Query};
|
||||
use prepare::prepare_mock_db;
|
||||
|
||||
#[tokio::test]
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[workspace]
|
||||
members = [".", "api", "core", "entity", "migration"]
|
||||
members = [".", "api", "service", "entity", "migration"]
|
||||
|
||||
[dependencies]
|
||||
axum-example-api = { path = "api" }
|
||||
|
@ -4,15 +4,15 @@
|
||||
|
||||
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
|
||||
|
||||
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-postgres",` line)
|
||||
1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-postgres",` line)
|
||||
|
||||
1. Execute `cargo run` to start the server
|
||||
|
||||
1. Visit [localhost:8000](http://localhost:8000) in browser
|
||||
|
||||
Run mock test on the core logic crate:
|
||||
Run mock test on the service logic crate:
|
||||
|
||||
```bash
|
||||
cd core
|
||||
cd service
|
||||
cargo test --features mock
|
||||
```
|
||||
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
axum-example-core = { path = "../core" }
|
||||
axum-example-service = { path = "../service" }
|
||||
tokio = { version = "1.23.0", features = ["full"] }
|
||||
axum = "0.6.1"
|
||||
tower = "0.4.13"
|
||||
|
@ -7,7 +7,7 @@ use axum::{
|
||||
routing::{get, get_service, post},
|
||||
Router, Server,
|
||||
};
|
||||
use axum_example_core::{
|
||||
use axum_example_service::{
|
||||
sea_orm::{Database, DatabaseConnection},
|
||||
Mutation as MutationCore, Query as QueryCore,
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "axum-example-core"
|
||||
name = "axum-example-service"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
@ -1,6 +1,6 @@
|
||||
mod prepare;
|
||||
|
||||
use axum_example_core::{Mutation, Query};
|
||||
use axum_example_service::{Mutation, Query};
|
||||
use entity::post;
|
||||
use prepare::prepare_mock_db;
|
||||
|
@ -7,7 +7,7 @@ publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[workspace]
|
||||
members = [".", "api", "core", "entity", "migration"]
|
||||
members = [".", "api", "service", "entity", "migration"]
|
||||
|
||||
[dependencies]
|
||||
graphql-example-api = { path = "api" }
|
||||
|
@ -6,15 +6,15 @@
|
||||
|
||||
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
|
||||
|
||||
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-sqlite",` line)
|
||||
1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-sqlite",` line)
|
||||
|
||||
1. Execute `cargo run` to start the server
|
||||
|
||||
1. Visit [localhost:3000/api/graphql](http://localhost:3000/api/graphql) in browser
|
||||
|
||||
Run mock test on the core logic crate:
|
||||
Run mock test on the service logic crate:
|
||||
|
||||
```bash
|
||||
cd core
|
||||
cd service
|
||||
cargo test --features mock
|
||||
```
|
||||
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
graphql-example-core = { path = "../core" }
|
||||
graphql-example-service = { path = "../service" }
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
axum = "0.5.1"
|
||||
dotenvy = "0.15.0"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use graphql_example_core::sea_orm::DatabaseConnection;
|
||||
use graphql_example_service::sea_orm::DatabaseConnection;
|
||||
|
||||
pub struct Database {
|
||||
pub connection: DatabaseConnection,
|
||||
@ -6,7 +6,7 @@ pub struct Database {
|
||||
|
||||
impl Database {
|
||||
pub async fn new() -> Self {
|
||||
let connection = graphql_example_core::sea_orm::Database::connect(
|
||||
let connection = graphql_example_service::sea_orm::Database::connect(
|
||||
std::env::var("DATABASE_URL").unwrap(),
|
||||
)
|
||||
.await
|
||||
|
@ -1,7 +1,7 @@
|
||||
use async_graphql::{Context, Object, Result};
|
||||
use entity::async_graphql::{self, InputObject, SimpleObject};
|
||||
use entity::note;
|
||||
use graphql_example_core::Mutation;
|
||||
use graphql_example_service::Mutation;
|
||||
|
||||
use crate::db::Database;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use async_graphql::{Context, Object, Result};
|
||||
use entity::{async_graphql, note};
|
||||
use graphql_example_core::Query;
|
||||
use graphql_example_service::Query;
|
||||
|
||||
use crate::db::Database;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "graphql-example-core"
|
||||
name = "graphql-example-service"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
@ -1,7 +1,7 @@
|
||||
mod prepare;
|
||||
|
||||
use entity::note;
|
||||
use graphql_example_core::{Mutation, Query};
|
||||
use graphql_example_service::{Mutation, Query};
|
||||
use prepare::prepare_mock_db;
|
||||
|
||||
#[tokio::test]
|
@ -6,7 +6,7 @@ publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[workspace]
|
||||
members = [".", "api", "core", "entity", "migration"]
|
||||
members = [".", "api", "service", "entity", "migration"]
|
||||
|
||||
[dependencies]
|
||||
jsonrpsee-example-api = { path = "api" }
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
|
||||
|
||||
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-sqlite",` line)
|
||||
1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-sqlite",` line)
|
||||
|
||||
1. Execute `cargo run` to start the server
|
||||
|
||||
@ -63,9 +63,9 @@ curl --location --request POST 'http://127.0.0.1:8000' \
|
||||
|
||||
```
|
||||
|
||||
Run mock test on the core logic crate:
|
||||
Run mock test on the service logic crate:
|
||||
|
||||
```bash
|
||||
cd core
|
||||
cd service
|
||||
cargo test --features mock
|
||||
```
|
||||
|
@ -5,7 +5,7 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
jsonrpsee-example-core = { path = "../core" }
|
||||
jsonrpsee-example-service = { path = "../service" }
|
||||
jsonrpsee = { version = "0.8.0", features = ["full"] }
|
||||
jsonrpsee-core = "0.9.0"
|
||||
tokio = { version = "1.8.0", features = ["full"] }
|
||||
|
@ -6,8 +6,8 @@ use jsonrpsee::core::{async_trait, RpcResult};
|
||||
use jsonrpsee::http_server::HttpServerBuilder;
|
||||
use jsonrpsee::proc_macros::rpc;
|
||||
use jsonrpsee::types::error::CallError;
|
||||
use jsonrpsee_example_core::sea_orm::{Database, DatabaseConnection};
|
||||
use jsonrpsee_example_core::{Mutation, Query};
|
||||
use jsonrpsee_example_service::sea_orm::{Database, DatabaseConnection};
|
||||
use jsonrpsee_example_service::{Mutation, Query};
|
||||
use log::info;
|
||||
use migration::{Migrator, MigratorTrait};
|
||||
use simplelog::*;
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "jsonrpsee-example-core"
|
||||
name = "jsonrpsee-example-service"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
79
examples/jsonrpsee_example/service/tests/mock.rs
Normal file
79
examples/jsonrpsee_example/service/tests/mock.rs
Normal file
@ -0,0 +1,79 @@
|
||||
mod prepare;
|
||||
|
||||
use entity::post;
|
||||
use jsonrpsee_example_service::{Mutation, Query};
|
||||
use prepare::prepare_mock_db;
|
||||
|
||||
#[tokio::test]
|
||||
async fn main() {
|
||||
let db = &prepare_mock_db();
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 5);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::create_post(
|
||||
db,
|
||||
post::Model {
|
||||
id: 0,
|
||||
title: "Title D".to_owned(),
|
||||
text: "Text D".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::ActiveModel {
|
||||
id: sea_orm::ActiveValue::Unchanged(6),
|
||||
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
|
||||
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::update_post_by_id(
|
||||
db,
|
||||
1,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_post(db, 5).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_all_posts(db).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 5);
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[workspace]
|
||||
members = [".", "api", "core", "entity", "migration"]
|
||||
members = [".", "api", "service", "entity", "migration"]
|
||||
|
||||
[dependencies]
|
||||
poem-example-api = { path = "api" }
|
||||
|
@ -4,15 +4,15 @@
|
||||
|
||||
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
|
||||
|
||||
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-sqlite",` line)
|
||||
1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-sqlite",` line)
|
||||
|
||||
1. Execute `cargo run` to start the server
|
||||
|
||||
1. Visit [localhost:8000](http://localhost:8000) in browser after seeing the `server started` line
|
||||
|
||||
Run mock test on the core logic crate:
|
||||
Run mock test on the service logic crate:
|
||||
|
||||
```bash
|
||||
cd core
|
||||
cd service
|
||||
cargo test --features mock
|
||||
```
|
||||
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
poem-example-core = { path = "../core" }
|
||||
poem-example-service = { path = "../service" }
|
||||
tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] }
|
||||
poem = { version = "1.2.33", features = ["static-files"] }
|
||||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
|
||||
|
@ -8,7 +8,7 @@ use poem::http::StatusCode;
|
||||
use poem::listener::TcpListener;
|
||||
use poem::web::{Data, Form, Html, Path, Query};
|
||||
use poem::{get, handler, post, EndpointExt, Error, IntoResponse, Result, Route, Server};
|
||||
use poem_example_core::{
|
||||
use poem_example_service::{
|
||||
sea_orm::{Database, DatabaseConnection},
|
||||
Mutation as MutationCore, Query as QueryCore,
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "poem-example-core"
|
||||
name = "poem-example-service"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
@ -1,7 +1,7 @@
|
||||
mod prepare;
|
||||
|
||||
use actix3_example_core::{Mutation, Query};
|
||||
use entity::post;
|
||||
use poem_example_service::{Mutation, Query};
|
||||
use prepare::prepare_mock_db;
|
||||
|
||||
#[tokio::test]
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[workspace]
|
||||
members = [".", "api", "core", "entity", "migration"]
|
||||
members = [".", "api", "service", "entity", "migration"]
|
||||
|
||||
[dependencies]
|
||||
rocket-example-api = { path = "api" }
|
||||
|
@ -4,15 +4,15 @@
|
||||
|
||||
1. Modify the `url` var in `api/Rocket.toml` to point to your chosen database
|
||||
|
||||
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-postgres",` line)
|
||||
1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-postgres",` line)
|
||||
|
||||
1. Execute `cargo run` to start the server
|
||||
|
||||
1. Visit [localhost:8000](http://localhost:8000) in browser after seeing the `🚀 Rocket has launched from http://localhost:8000` line
|
||||
|
||||
Run mock test on the core logic crate:
|
||||
Run mock test on the service logic crate:
|
||||
|
||||
```bash
|
||||
cd core
|
||||
cd service
|
||||
cargo test --features mock
|
||||
```
|
||||
|
@ -8,7 +8,7 @@ publish = false
|
||||
[dependencies]
|
||||
async-stream = { version = "0.3" }
|
||||
async-trait = { version = "0.1" }
|
||||
rocket-example-core = { path = "../core" }
|
||||
rocket-example-service = { path = "../service" }
|
||||
futures = { version = "0.3" }
|
||||
futures-util = { version = "0.3" }
|
||||
rocket = { version = "0.5.0-rc.1", features = [
|
||||
|
@ -8,7 +8,7 @@ use rocket::request::FlashMessage;
|
||||
use rocket::response::{Flash, Redirect};
|
||||
use rocket::{Build, Request, Rocket};
|
||||
use rocket_dyn_templates::Template;
|
||||
use rocket_example_core::{Mutation, Query};
|
||||
use rocket_example_service::{Mutation, Query};
|
||||
use serde_json::json;
|
||||
|
||||
use migration::MigratorTrait;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use rocket_example_core::sea_orm;
|
||||
use rocket_example_service::sea_orm;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use sea_orm::ConnectOptions;
|
||||
|
@ -1,79 +0,0 @@
|
||||
mod prepare;
|
||||
|
||||
use entity::post;
|
||||
use prepare::prepare_mock_db;
|
||||
use rocket_example_core::{Mutation, Query};
|
||||
|
||||
#[tokio::test]
|
||||
async fn main() {
|
||||
let db = &prepare_mock_db();
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 5);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::create_post(
|
||||
db,
|
||||
post::Model {
|
||||
id: 0,
|
||||
title: "Title D".to_owned(),
|
||||
text: "Text D".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::ActiveModel {
|
||||
id: sea_orm::ActiveValue::Unchanged(6),
|
||||
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
|
||||
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::update_post_by_id(
|
||||
db,
|
||||
1,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_post(db, 5).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_all_posts(db).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 5);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "rocket-example-core"
|
||||
name = "rocket-example-service"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
79
examples/rocket_example/service/tests/mock.rs
Normal file
79
examples/rocket_example/service/tests/mock.rs
Normal file
@ -0,0 +1,79 @@
|
||||
mod prepare;
|
||||
|
||||
use entity::post;
|
||||
use prepare::prepare_mock_db;
|
||||
use rocket_example_service::{Mutation, Query};
|
||||
|
||||
#[tokio::test]
|
||||
async fn main() {
|
||||
let db = &prepare_mock_db();
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 5);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::create_post(
|
||||
db,
|
||||
post::Model {
|
||||
id: 0,
|
||||
title: "Title D".to_owned(),
|
||||
text: "Text D".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::ActiveModel {
|
||||
id: sea_orm::ActiveValue::Unchanged(6),
|
||||
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
|
||||
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::update_post_by_id(
|
||||
db,
|
||||
1,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_post(db, 5).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_all_posts(db).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 5);
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[workspace]
|
||||
members = [".", "api", "core", "entity", "migration", "dto"]
|
||||
members = [".", "api", "service", "entity", "migration", "dto"]
|
||||
|
||||
[dependencies]
|
||||
rocket-example-api = { path = "api" }
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
1. Modify the `url` var in `api/Rocket.toml` to point to your chosen database
|
||||
|
||||
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-postgres",` line)
|
||||
1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-postgres",` line)
|
||||
|
||||
1. Execute `cargo run` to start the server
|
||||
|
||||
|
@ -8,7 +8,7 @@ publish = false
|
||||
[dependencies]
|
||||
async-stream = { version = "0.3" }
|
||||
async-trait = { version = "0.1" }
|
||||
rocket-example-core = { path = "../core" }
|
||||
rocket-example-service = { path = "../service" }
|
||||
futures = { version = "0.3" }
|
||||
futures-util = { version = "0.3" }
|
||||
rocket = { version = "0.5.0-rc.1", features = [
|
||||
|
@ -1,6 +1,6 @@
|
||||
use dto::dto;
|
||||
use rocket::serde::json::Json;
|
||||
use rocket_example_core::{Mutation, Query};
|
||||
use rocket_example_service::{Mutation, Query};
|
||||
|
||||
use sea_orm_rocket::Connection;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use rocket_example_core::sea_orm;
|
||||
use rocket_example_service::sea_orm;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use sea_orm::ConnectOptions;
|
||||
|
@ -1,79 +0,0 @@
|
||||
mod prepare;
|
||||
|
||||
use entity::post;
|
||||
use prepare::prepare_mock_db;
|
||||
use rocket_example_core::{Mutation, Query};
|
||||
|
||||
#[tokio::test]
|
||||
async fn main() {
|
||||
let db = &prepare_mock_db();
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 5);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::create_post(
|
||||
db,
|
||||
post::Model {
|
||||
id: 0,
|
||||
title: "Title D".to_owned(),
|
||||
text: "Text D".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::ActiveModel {
|
||||
id: sea_orm::ActiveValue::Unchanged(6),
|
||||
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
|
||||
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::update_post_by_id(
|
||||
db,
|
||||
1,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_post(db, 5).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_all_posts(db).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 5);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "rocket-example-core"
|
||||
name = "rocket-example-service"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
79
examples/rocket_okapi_example/service/tests/mock.rs
Normal file
79
examples/rocket_okapi_example/service/tests/mock.rs
Normal file
@ -0,0 +1,79 @@
|
||||
mod prepare;
|
||||
|
||||
use entity::post;
|
||||
use prepare::prepare_mock_db;
|
||||
use rocket_example_service::{Mutation, Query};
|
||||
|
||||
#[tokio::test]
|
||||
async fn main() {
|
||||
let db = &prepare_mock_db();
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 5);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::create_post(
|
||||
db,
|
||||
post::Model {
|
||||
id: 0,
|
||||
title: "Title D".to_owned(),
|
||||
text: "Text D".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::ActiveModel {
|
||||
id: sea_orm::ActiveValue::Unchanged(6),
|
||||
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
|
||||
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::update_post_by_id(
|
||||
db,
|
||||
1,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_post(db, 5).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_all_posts(db).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 5);
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[workspace]
|
||||
members = [".", "api", "core", "entity", "migration"]
|
||||
members = [".", "api", "service", "entity", "migration"]
|
||||
|
||||
[dependencies]
|
||||
salvo-example-api = { path = "api" }
|
||||
|
@ -4,15 +4,15 @@
|
||||
|
||||
1. Modify the `DATABASE_URL` var in `.env` to point to your chosen database
|
||||
|
||||
1. Turn on the appropriate database feature for your chosen db in `core/Cargo.toml` (the `"sqlx-sqlite",` line)
|
||||
1. Turn on the appropriate database feature for your chosen db in `service/Cargo.toml` (the `"sqlx-sqlite",` line)
|
||||
|
||||
1. Execute `cargo run` to start the server
|
||||
|
||||
1. Visit [localhost:8000](http://localhost:8000) in browser after seeing the `server started` line
|
||||
|
||||
Run mock test on the core logic crate:
|
||||
Run mock test on the service logic crate:
|
||||
|
||||
```bash
|
||||
cd core
|
||||
cd service
|
||||
cargo test --features mock
|
||||
```
|
||||
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
salvo-example-core = { path = "../core" }
|
||||
salvo-example-service = { path = "../service" }
|
||||
tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] }
|
||||
salvo = { version = "0.27", features = ["affix", "serve-static"] }
|
||||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
|
||||
|
@ -6,7 +6,7 @@ use salvo::extra::affix;
|
||||
use salvo::extra::serve_static::DirHandler;
|
||||
use salvo::prelude::*;
|
||||
use salvo::writer::Text;
|
||||
use salvo_example_core::{
|
||||
use salvo_example_service::{
|
||||
sea_orm::{Database, DatabaseConnection},
|
||||
Mutation, Query,
|
||||
};
|
||||
|
@ -1,79 +0,0 @@
|
||||
mod prepare;
|
||||
|
||||
use entity::post;
|
||||
use prepare::prepare_mock_db;
|
||||
use salvo_example_core::{Mutation, Query};
|
||||
|
||||
#[tokio::test]
|
||||
async fn main() {
|
||||
let db = &prepare_mock_db();
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 1).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Query::find_post_by_id(db, 5).await.unwrap().unwrap();
|
||||
|
||||
assert_eq!(post.id, 5);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::create_post(
|
||||
db,
|
||||
post::Model {
|
||||
id: 0,
|
||||
title: "Title D".to_owned(),
|
||||
text: "Text D".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::ActiveModel {
|
||||
id: sea_orm::ActiveValue::Unchanged(6),
|
||||
title: sea_orm::ActiveValue::Unchanged("Title D".to_owned()),
|
||||
text: sea_orm::ActiveValue::Unchanged("Text D".to_owned())
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let post = Mutation::update_post_by_id(
|
||||
db,
|
||||
1,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
post,
|
||||
post::Model {
|
||||
id: 1,
|
||||
title: "New Title A".to_owned(),
|
||||
text: "New Text A".to_owned(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_post(db, 5).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 1);
|
||||
}
|
||||
|
||||
{
|
||||
let result = Mutation::delete_all_posts(db).await.unwrap();
|
||||
|
||||
assert_eq!(result.rows_affected, 5);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "salvo-example-core"
|
||||
name = "salvo-example-service"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
@ -1,8 +1,8 @@
|
||||
mod prepare;
|
||||
|
||||
use actix_example_core::{Mutation, Query};
|
||||
use entity::post;
|
||||
use prepare::prepare_mock_db;
|
||||
use salvo_example_service::{Mutation, Query};
|
||||
|
||||
#[tokio::test]
|
||||
async fn main() {
|
@ -7,7 +7,7 @@ publish = false
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[workspace]
|
||||
members = [".", "api", "core", "entity", "migration"]
|
||||
members = [".", "api", "service", "entity", "migration"]
|
||||
|
||||
[dependencies]
|
||||
tonic-example-api = { path = "api" }
|
||||
|
@ -14,9 +14,9 @@ run client using
|
||||
cargo run --bin client
|
||||
```
|
||||
|
||||
Run mock test on the core logic crate:
|
||||
Run mock test on the service logic crate:
|
||||
|
||||
```bash
|
||||
cd core
|
||||
cd service
|
||||
cargo test --features mock
|
||||
```
|
||||
|
@ -5,7 +5,7 @@ edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
tonic-example-core = { path = "../core" }
|
||||
tonic-example-service = { path = "../service" }
|
||||
tonic = "0.7"
|
||||
tokio = { version = "1.17", features = ["macros", "rt-multi-thread", "full"] }
|
||||
entity = { path = "../entity" }
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user