From b84a1f640cb58a2ad68951d7c1726ae43cd88f91 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:36:33 +0100 Subject: [PATCH 1/3] chore: loco 0.14.0 + shuttle 0.51.0 --- loco/hello-world/.cargo/config.toml | 3 ++ loco/hello-world/.devcontainer/.env | 0 loco/hello-world/.devcontainer/Dockerfile | 8 ---- .../.devcontainer/devcontainer.json | 9 ----- .../.devcontainer/docker-compose.yml | 12 ------ loco/hello-world/.github/workflows/ci.yaml | 40 ++++++++++++++----- loco/hello-world/.gitignore | 8 ++-- loco/hello-world/.rustfmt.toml | 2 + loco/hello-world/Cargo.toml | 39 ++++++++++-------- loco/hello-world/README.md | 25 ++++++------ loco/hello-world/Shuttle.toml | 9 +++++ loco/hello-world/config/development.yaml | 38 ++++++------------ loco/hello-world/config/production.yaml | 38 ++++++------------ loco/hello-world/config/test.yaml | 33 +++++---------- loco/hello-world/src/app.rs | 33 ++++++++++----- loco/hello-world/src/bin/shuttle.rs | 15 +++++-- loco/hello-world/src/controllers/home.rs | 4 +- loco/hello-world/src/initializers/mod.rs | 1 + loco/hello-world/src/lib.rs | 2 + loco/hello-world/src/tasks/mod.rs | 1 + loco/hello-world/tests/mod.rs | 1 + loco/hello-world/tests/requests/home.rs | 23 +++-------- .../snapshots/can_get_home@home_request.snap | 8 ---- loco/hello-world/tests/tasks/mod.rs | 1 + 24 files changed, 169 insertions(+), 184 deletions(-) delete mode 100644 loco/hello-world/.devcontainer/.env delete mode 100644 loco/hello-world/.devcontainer/Dockerfile delete mode 100644 loco/hello-world/.devcontainer/devcontainer.json delete mode 100644 loco/hello-world/.devcontainer/docker-compose.yml create mode 100644 loco/hello-world/.rustfmt.toml create mode 100644 loco/hello-world/Shuttle.toml create mode 100644 loco/hello-world/src/initializers/mod.rs create mode 100644 loco/hello-world/src/tasks/mod.rs delete mode 100644 loco/hello-world/tests/requests/snapshots/can_get_home@home_request.snap create mode 100644 loco/hello-world/tests/tasks/mod.rs diff --git a/loco/hello-world/.cargo/config.toml b/loco/hello-world/.cargo/config.toml index 8b040c15..56012377 100644 --- a/loco/hello-world/.cargo/config.toml +++ b/loco/hello-world/.cargo/config.toml @@ -1,2 +1,5 @@ [alias] loco = "run --bin hello_world-cli --" +loco-tool = "run --" + +playground = "run --example playground" \ No newline at end of file diff --git a/loco/hello-world/.devcontainer/.env b/loco/hello-world/.devcontainer/.env deleted file mode 100644 index e69de29b..00000000 diff --git a/loco/hello-world/.devcontainer/Dockerfile b/loco/hello-world/.devcontainer/Dockerfile deleted file mode 100644 index fd43f09b..00000000 --- a/loco/hello-world/.devcontainer/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM mcr.microsoft.com/vscode/devcontainers/rust:0-1 - -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends postgresql-client \ - && cargo install cargo-insta \ - && chown -R vscode /usr/local/cargo - -COPY .env /.env diff --git a/loco/hello-world/.devcontainer/devcontainer.json b/loco/hello-world/.devcontainer/devcontainer.json deleted file mode 100644 index 6aecc100..00000000 --- a/loco/hello-world/.devcontainer/devcontainer.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "Loco", - "dockerComposeFile": "docker-compose.yml", - "service": "app", - "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", - "forwardPorts": [ - 8000 - ] -} \ No newline at end of file diff --git a/loco/hello-world/.devcontainer/docker-compose.yml b/loco/hello-world/.devcontainer/docker-compose.yml deleted file mode 100644 index 3985587e..00000000 --- a/loco/hello-world/.devcontainer/docker-compose.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: "3" - -services: - app: - build: - context: . - dockerfile: Dockerfile - command: sleep infinity - volumes: - - ../..:/workspaces:cached - env_file: - - .env diff --git a/loco/hello-world/.github/workflows/ci.yaml b/loco/hello-world/.github/workflows/ci.yaml index 15ee4a6a..75ba8a5e 100644 --- a/loco/hello-world/.github/workflows/ci.yaml +++ b/loco/hello-world/.github/workflows/ci.yaml @@ -21,11 +21,9 @@ jobs: steps: - name: Checkout the code uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 + - uses: dtolnay/rust-toolchain@stable with: - profile: ${{ env.TOOLCHAIN_PROFILE }} toolchain: ${{ env.RUST_TOOLCHAIN }} - override: true components: rustfmt - name: Run cargo fmt uses: actions-rs/cargo@v1 @@ -43,11 +41,9 @@ jobs: steps: - name: Checkout the code uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 + - uses: dtolnay/rust-toolchain@stable with: - profile: ${{ env.TOOLCHAIN_PROFILE }} toolchain: ${{ env.RUST_TOOLCHAIN }} - override: true - name: Setup Rust cache uses: Swatinem/rust-cache@v2 - name: Run cargo clippy @@ -62,15 +58,37 @@ jobs: permissions: contents: read + + services: + redis: + image: redis + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - "6379:6379" + postgres: + image: postgres + env: + POSTGRES_DB: postgres_test + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + ports: + - "5432:5432" + # Set health checks to wait until postgres has started + options: --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 steps: - name: Checkout the code uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 + - uses: dtolnay/rust-toolchain@stable with: - profile: ${{ env.TOOLCHAIN_PROFILE }} toolchain: ${{ env.RUST_TOOLCHAIN }} - override: true - name: Setup Rust cache uses: Swatinem/rust-cache@v2 - name: Run cargo test @@ -78,3 +96,7 @@ jobs: with: command: test args: --all-features --all + env: + REDIS_URL: redis://localhost:${{job.services.redis.ports[6379]}} + DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres_test + diff --git a/loco/hello-world/.gitignore b/loco/hello-world/.gitignore index 5d5402d5..b7372874 100644 --- a/loco/hello-world/.gitignore +++ b/loco/hello-world/.gitignore @@ -1,16 +1,16 @@ **/config/local.yaml +**/config/*.local.yaml +**/config/production.yaml # Generated by Cargo # will have compiled files and executables debug/ target/ -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock - # These are backup files generated by rustfmt **/*.rs.bk # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + +*.sqlite diff --git a/loco/hello-world/.rustfmt.toml b/loco/hello-world/.rustfmt.toml new file mode 100644 index 00000000..d862e081 --- /dev/null +++ b/loco/hello-world/.rustfmt.toml @@ -0,0 +1,2 @@ +max_width = 100 +use_small_heuristics = "Default" diff --git a/loco/hello-world/Cargo.toml b/loco/hello-world/Cargo.toml index 938594dc..d6431aaf 100644 --- a/loco/hello-world/Cargo.toml +++ b/loco/hello-world/Cargo.toml @@ -1,24 +1,32 @@ [workspace] [package] -name = "hello_world" +name = "hello-world" version = "0.1.0" edition = "2021" +publish = false +default-run = "hello_world-cli" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] +[workspace.dependencies] +loco-rs = { version = "0.14.0", default-features = false } -async-trait = "0.1.74" -axum = "0.7.1" -loco-rs = { version = "0.9.0", default-features = false, features = ["cli"] } -shuttle-axum = { version = "0.51.0", default-features = false, features = ["axum-0-7"] } +[dependencies] +shuttle-axum = "0.51.0" shuttle-runtime = { version = "0.51.0", default-features = false } -serde = "*" -serde_json = "*" -tokio = "1.33.0" -tracing = "0.1.40" + +loco-rs = { workspace = true , features = ["cli"] } +serde = { version = "1", features = ["derive"] } +serde_json = { version = "1" } +tokio = { version = "1.33.0", default-features = false, features = [ + "rt-multi-thread", +] } +async-trait = { version = "0.1.74" } +axum = { version = "0.8.1" } +tracing = { version = "0.1.40" } tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json"] } +regex = { version = "1.11.1" } [[bin]] name = "hello_world-cli" @@ -30,10 +38,7 @@ name = "hello_world" path = "src/bin/shuttle.rs" [dev-dependencies] -serial_test = "*" -rstest = "*" -loco-rs = { version = "0.9.0", default-features = false, features = [ - "testing", - "cli", -] } -insta = { version = "*", features = ["redactions", "yaml", "filters"] } +loco-rs = { workspace = true, features = ["testing"] } +serial_test = { version = "3.1.1" } +rstest = { version = "0.21.0" } +insta = { version = "1.34.0", features = ["redactions", "yaml", "filters"] } \ No newline at end of file diff --git a/loco/hello-world/README.md b/loco/hello-world/README.md index 43915f96..3886fa67 100644 --- a/loco/hello-world/README.md +++ b/loco/hello-world/README.md @@ -1,18 +1,9 @@ -# Shuttle Loco template :train: +# Welcome to Loco :train: -Welcome to the [Loco](https://loco.rs) Hello World Shuttle Template, designed with a focus on controllers and views (response schema). This minimalistic template comes with several features to kickstart your project: +[Loco](https://loco.rs) is a web and API framework running on Rust. -## REST API Service without a Database - -* **Controllers:** Handle web requests parameters, body, validation, and render a response that is content-aware. We use Axum for the best performance, simplicity, and extensibility. Controllers also allow you to easily build middlewares, which can be used to add logic such as authentication, logging, or error handling before passing requests to the main controller actions. -* **Views:** Loco can integrate with templating engines to generate dynamic HTML content from templates. -* **Background Jobs:** Perform compute or I/O intensive jobs in the background with a Redis backed queue, or with threads. Implementing a worker is as simple as implementing a perform function for the Worker trait. -* **Scheduler:** Simplifies the traditional, often cumbersome crontab system, making it easier and more elegant to schedule tasks or shell scripts. -* **Mailers:** A mailer will deliver emails in the background using the existing loco background worker infrastructure. It will all be seamless for you. -* **Storage:** In Loco Storage, we facilitate working with files through multiple operations. Storage can be in-memory, on disk, or use cloud services such as AWS S3, GCP, and Azure. -* **Cache:** Loco provides an cache layer to improve application performance by storing frequently accessed data. - -So see more Loco features, check out our [documentation website](https://loco.rs/docs/getting-started/tour/). +This is the **SaaS starter** which includes a `User` model and authentication based on JWT. +It also include configuration sections that help you pick either a frontend or a server-side template set up for your fullstack server. ## Quick Start @@ -21,3 +12,11 @@ To launch your app, simply use the following command: ```sh shuttle run ``` + +## Full Stack Serving + +You can check your [configuration](config/development.yaml) to pick either frontend setup or server-side rendered template, and activate the relevant configuration sections. + +## Getting help + +Check out [a quick tour](https://loco.rs/docs/getting-started/tour/) or [the complete guide](https://loco.rs/docs/getting-started/guide/). diff --git a/loco/hello-world/Shuttle.toml b/loco/hello-world/Shuttle.toml new file mode 100644 index 00000000..6af3620b --- /dev/null +++ b/loco/hello-world/Shuttle.toml @@ -0,0 +1,9 @@ +[deploy] +include = [ + "config/production.yaml" +] + +[build] +assets = [ + "config/production.yaml" +] diff --git a/loco/hello-world/config/development.yaml b/loco/hello-world/config/development.yaml index 4f513991..d3b57319 100644 --- a/loco/hello-world/config/development.yaml +++ b/loco/hello-world/config/development.yaml @@ -4,9 +4,11 @@ logger: # Enable or disable logging. enable: true + # Enable pretty backtrace (sets RUST_BACKTRACE=1) + pretty_backtrace: true # Log level, options: trace, debug, info, warn or error. level: debug - # Define the logging format. options: compact, pretty or Json + # Define the logging format. options: compact, pretty or json format: compact # By default the logger has filtering only logs that came from your code or logs that came from `loco` framework. to see all third party libraries # Uncomment the line below to override to see all third party libraries you can enable this config and override the logger filters. @@ -15,31 +17,17 @@ logger: # Web server configuration server: # Port on which the server will listen. the server binding is 0.0.0.0:{PORT} - port: 8000 + port: 5150 + # Binding for the server (which interface to bind to) + binding: localhost # The UI hostname or IP address that mailers will point to. host: http://localhost # Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block middlewares: - # Enable Etag cache header middleware - etag: - enable: true - # Allows to limit the payload size request. payload that bigger than this file will blocked the request. - limit_payload: - # Enable/Disable the middleware. - enable: true - # the limit size. can be b,kb,kib,mb,mib,gb,gib - body_limit: 5mb - # Generating a unique request ID and enhancing logging with additional information such as the start and completion of request processing, latency, status code, and other request details. - logger: - # Enable/Disable the middleware. - enable: true - # when your code is panicked, the request still returns 500 status code. - catch_panic: - # Enable/Disable the middleware. - enable: true - # Timeout for incoming requests middleware. requests that take more time from the configuration will cute and 408 status code will returned. - timeout_request: - # Enable/Disable the middleware. - enable: false - # Duration time in milliseconds. - timeout: 5000 + +# Initializers Configuration +# initializers: +# oauth2: +# authorization_code: # Authorization code grant type +# - client_identifier: google # Identifier for the OAuth2 provider. Replace 'google' with your provider's name if different, must be unique within the oauth2 config. +# ... other fields diff --git a/loco/hello-world/config/production.yaml b/loco/hello-world/config/production.yaml index 4f513991..d3b57319 100644 --- a/loco/hello-world/config/production.yaml +++ b/loco/hello-world/config/production.yaml @@ -4,9 +4,11 @@ logger: # Enable or disable logging. enable: true + # Enable pretty backtrace (sets RUST_BACKTRACE=1) + pretty_backtrace: true # Log level, options: trace, debug, info, warn or error. level: debug - # Define the logging format. options: compact, pretty or Json + # Define the logging format. options: compact, pretty or json format: compact # By default the logger has filtering only logs that came from your code or logs that came from `loco` framework. to see all third party libraries # Uncomment the line below to override to see all third party libraries you can enable this config and override the logger filters. @@ -15,31 +17,17 @@ logger: # Web server configuration server: # Port on which the server will listen. the server binding is 0.0.0.0:{PORT} - port: 8000 + port: 5150 + # Binding for the server (which interface to bind to) + binding: localhost # The UI hostname or IP address that mailers will point to. host: http://localhost # Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block middlewares: - # Enable Etag cache header middleware - etag: - enable: true - # Allows to limit the payload size request. payload that bigger than this file will blocked the request. - limit_payload: - # Enable/Disable the middleware. - enable: true - # the limit size. can be b,kb,kib,mb,mib,gb,gib - body_limit: 5mb - # Generating a unique request ID and enhancing logging with additional information such as the start and completion of request processing, latency, status code, and other request details. - logger: - # Enable/Disable the middleware. - enable: true - # when your code is panicked, the request still returns 500 status code. - catch_panic: - # Enable/Disable the middleware. - enable: true - # Timeout for incoming requests middleware. requests that take more time from the configuration will cute and 408 status code will returned. - timeout_request: - # Enable/Disable the middleware. - enable: false - # Duration time in milliseconds. - timeout: 5000 + +# Initializers Configuration +# initializers: +# oauth2: +# authorization_code: # Authorization code grant type +# - client_identifier: google # Identifier for the OAuth2 provider. Replace 'google' with your provider's name if different, must be unique within the oauth2 config. +# ... other fields diff --git a/loco/hello-world/config/test.yaml b/loco/hello-world/config/test.yaml index 67603bba..863ff0ca 100644 --- a/loco/hello-world/config/test.yaml +++ b/loco/hello-world/config/test.yaml @@ -4,9 +4,11 @@ logger: # Enable or disable logging. enable: false + # Enable pretty backtrace (sets RUST_BACKTRACE=1) + pretty_backtrace: true # Log level, options: trace, debug, info, warn or error. level: debug - # Define the logging format. options: compact, pretty or Json + # Define the logging format. options: compact, pretty or json format: compact # By default the logger has filtering only logs that came from your code or logs that came from `loco` framework. to see all third party libraries # Uncomment the line below to override to see all third party libraries you can enable this config and override the logger filters. @@ -15,28 +17,15 @@ logger: # Web server configuration server: # Port on which the server will listen. the server binding is 0.0.0.0:{PORT} - port: 8000 + port: 5150 # The UI hostname or IP address that mailers will point to. host: http://localhost # Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block middlewares: - # Allows to limit the payload size request. payload that bigger than this file will blocked the request. - limit_payload: - # Enable/Disable the middleware. - enable: true - # the limit size. can be b,kb,kib,mb,mib,gb,gib - body_limit: 5mb - # Generating a unique request ID and enhancing logging with additional information such as the start and completion of request processing, latency, status code, and other request details. - logger: - # Enable/Disable the middleware. - enable: true - # when your code is panicked, the request still returns 500 status code. - catch_panic: - # Enable/Disable the middleware. - enable: true - # Timeout for incoming requests middleware. requests that take more time from the configuration will cute and 408 status code will returned. - timeout_request: - # Enable/Disable the middleware. - enable: false - # Duration time in milliseconds. - timeout: 5000 + +# Initializers Configuration +# initializers: +# oauth2: +# authorization_code: # Authorization code grant type +# - client_identifier: google # Identifier for the OAuth2 provider. Replace 'google' with your provider's name if different, must be unique within the oauth2 config. +# ... other fields diff --git a/loco/hello-world/src/app.rs b/loco/hello-world/src/app.rs index 5068ff94..f20bd31b 100644 --- a/loco/hello-world/src/app.rs +++ b/loco/hello-world/src/app.rs @@ -1,15 +1,17 @@ use async_trait::async_trait; use loco_rs::{ - app::{AppContext, Hooks}, + app::{AppContext, Hooks, Initializer}, + bgworker::Queue, boot::{create_app, BootResult, StartMode}, + config::Config, controller::AppRoutes, environment::Environment, task::Tasks, - worker::Processor, Result, }; -use crate::controllers; +#[allow(unused_imports)] +use crate::{controllers, tasks}; pub struct App; #[async_trait] @@ -28,17 +30,28 @@ impl Hooks for App { ) } - async fn boot(mode: StartMode, environment: &Environment) -> Result { - create_app::(mode, environment).await + async fn boot( + mode: StartMode, + environment: &Environment, + config: Config, + ) -> Result { + create_app::(mode, environment, config).await + } + + async fn initializers(_ctx: &AppContext) -> Result>> { + Ok(vec![]) } fn routes(_ctx: &AppContext) -> AppRoutes { - AppRoutes::empty() - // .prefix("/api") + AppRoutes::with_default_routes() // controller routes below .add_route(controllers::home::routes()) } + async fn connect_workers(_ctx: &AppContext, _queue: &Queue) -> Result<()> { + Ok(()) + } - fn connect_workers<'a>(_p: &'a mut Processor, _ctx: &'a AppContext) {} - - fn register_tasks(_tasks: &mut Tasks) {} + #[allow(unused_variables)] + fn register_tasks(tasks: &mut Tasks) { + // tasks-inject (do not remove) + } } diff --git a/loco/hello-world/src/bin/shuttle.rs b/loco/hello-world/src/bin/shuttle.rs index c68f027e..42987fe7 100644 --- a/loco/hello-world/src/bin/shuttle.rs +++ b/loco/hello-world/src/bin/shuttle.rs @@ -1,16 +1,25 @@ -use hello_world::app::App; use loco_rs::boot::{create_app, StartMode}; use loco_rs::environment::Environment; +use hello_world::app::App; + +use shuttle_runtime::DeploymentMetadata; #[shuttle_runtime::main] async fn main( - #[shuttle_runtime::Metadata] meta: shuttle_runtime::DeploymentMetadata, + + #[shuttle_runtime::Metadata] meta: DeploymentMetadata, ) -> shuttle_axum::ShuttleAxum { + let environment = match meta.env { shuttle_runtime::Environment::Local => Environment::Development, shuttle_runtime::Environment::Deployment => Environment::Production, }; - let boot_result = create_app::(StartMode::ServerOnly, &environment) + + let config = environment + .load() + .expect("Failed to load configuration from the environment"); + + let boot_result = create_app::(StartMode::ServerOnly, &environment, config) .await .unwrap(); diff --git a/loco/hello-world/src/controllers/home.rs b/loco/hello-world/src/controllers/home.rs index 863b4b9b..0d6430f6 100644 --- a/loco/hello-world/src/controllers/home.rs +++ b/loco/hello-world/src/controllers/home.rs @@ -1,11 +1,13 @@ +use axum::debug_handler; use loco_rs::prelude::*; use crate::views::home::HomeResponse; +#[debug_handler] async fn current() -> Result { format::json(HomeResponse::new("loco")) } pub fn routes() -> Routes { - Routes::new().add("/", get(current)) + Routes::new().prefix("/api").add("/", get(current)) } diff --git a/loco/hello-world/src/initializers/mod.rs b/loco/hello-world/src/initializers/mod.rs new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/loco/hello-world/src/initializers/mod.rs @@ -0,0 +1 @@ + diff --git a/loco/hello-world/src/lib.rs b/loco/hello-world/src/lib.rs index 0827f2da..6389c422 100644 --- a/loco/hello-world/src/lib.rs +++ b/loco/hello-world/src/lib.rs @@ -1,3 +1,5 @@ pub mod app; pub mod controllers; +pub mod initializers; +pub mod tasks; pub mod views; diff --git a/loco/hello-world/src/tasks/mod.rs b/loco/hello-world/src/tasks/mod.rs new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/loco/hello-world/src/tasks/mod.rs @@ -0,0 +1 @@ + diff --git a/loco/hello-world/tests/mod.rs b/loco/hello-world/tests/mod.rs index c2e46cdd..c788ab7c 100644 --- a/loco/hello-world/tests/mod.rs +++ b/loco/hello-world/tests/mod.rs @@ -1 +1,2 @@ mod requests; +mod tasks; diff --git a/loco/hello-world/tests/requests/home.rs b/loco/hello-world/tests/requests/home.rs index 6a9246ad..4a843209 100644 --- a/loco/hello-world/tests/requests/home.rs +++ b/loco/hello-world/tests/requests/home.rs @@ -1,28 +1,15 @@ use hello_world::app::App; -use insta::assert_debug_snapshot; -use loco_rs::testing; +use loco_rs::testing::prelude::*; use serial_test::serial; -// TODO: see how to dedup / extract this to app-local test utils -// not to framework, because that would require a runtime dep on insta -macro_rules! configure_insta { - ($($expr:expr),*) => { - let mut settings = insta::Settings::clone_current(); - settings.set_prepend_module_to_snapshot(false); - settings.set_snapshot_suffix("home_request"); - let _guard = settings.bind_to_scope(); - }; -} - #[tokio::test] #[serial] async fn can_get_home() { - configure_insta!(); - - testing::request::(|request, _ctx| async move { - let notes = request.get("/").await; + request::(|request, _ctx| async move { + let res = request.get("/api").await; - assert_debug_snapshot!((notes.status_code(), notes.text())); + assert_eq!(res.status_code(), 200); + res.assert_json(&serde_json::json!({"app_name":"loco"})); }) .await; } diff --git a/loco/hello-world/tests/requests/snapshots/can_get_home@home_request.snap b/loco/hello-world/tests/requests/snapshots/can_get_home@home_request.snap deleted file mode 100644 index a686e3f4..00000000 --- a/loco/hello-world/tests/requests/snapshots/can_get_home@home_request.snap +++ /dev/null @@ -1,8 +0,0 @@ ---- -source: tests/requests/home.rs -expression: "(notes.status_code(), notes.text())" ---- -( - 200, - "{\"app_name\":\"loco\"}", -) diff --git a/loco/hello-world/tests/tasks/mod.rs b/loco/hello-world/tests/tasks/mod.rs new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/loco/hello-world/tests/tasks/mod.rs @@ -0,0 +1 @@ + From f476b61a39da3438ff02dce5e7cd99d26e1ccea9 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:43:33 +0100 Subject: [PATCH 2/3] fix: package name --- loco/hello-world/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loco/hello-world/Cargo.toml b/loco/hello-world/Cargo.toml index d6431aaf..1b825c2d 100644 --- a/loco/hello-world/Cargo.toml +++ b/loco/hello-world/Cargo.toml @@ -1,7 +1,7 @@ [workspace] [package] -name = "hello-world" +name = "hello_world" version = "0.1.0" edition = "2021" publish = false From a3e21e71b6959ad250962147899fe15aa66009ee Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:44:27 +0100 Subject: [PATCH 3/3] update gitignore from shuttle cli --- loco/hello-world/.gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/loco/hello-world/.gitignore b/loco/hello-world/.gitignore index b7372874..0af292ce 100644 --- a/loco/hello-world/.gitignore +++ b/loco/hello-world/.gitignore @@ -14,3 +14,6 @@ target/ *.pdb *.sqlite +/target +.shuttle* +Secrets*.toml