diff --git a/.commitlintrc.yaml b/.commitlintrc.yaml new file mode 100644 index 0000000..2316995 --- /dev/null +++ b/.commitlintrc.yaml @@ -0,0 +1,7 @@ +rules: + description-empty: # Description shouldn't be empty + level: warning + subject-empty: # Subject line should exist + level: error + type-empty: # Type must not be empty + level: error \ No newline at end of file diff --git a/.samoyed/commit-msg b/.samoyed/commit-msg new file mode 100755 index 0000000..f041635 --- /dev/null +++ b/.samoyed/commit-msg @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +commitlint --edit $1 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index e85cf6e..2b2a6d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,15 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 4 +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] [[package]] name = "async-channel" @@ -152,6 +161,16 @@ dependencies = [ "piper", ] +[[package]] +name = "cc" +version = "1.2.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" +dependencies = [ + "find-msvc-tools", + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.4" @@ -173,7 +192,6 @@ dependencies = [ "compio-buf", "compio-driver", "compio-log", - "compio-runtime", ] [[package]] @@ -219,28 +237,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "compio-runtime" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c1c71f011bdd9c8f30e97d877b606505ee6d241c7782cfaed172f66acbd9cd" -dependencies = [ - "async-task", - "compio-buf", - "compio-driver", - "compio-log", - "core_affinity", - "crossbeam-queue", - "futures-util", - "libc", - "once_cell", - "pin-project-lite", - "scoped-tls", - "slab", - "socket2", - "windows-sys", -] - [[package]] name = "concurrent-queue" version = "2.5.0" @@ -250,17 +246,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "core_affinity" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a034b3a7b624016c6e13f5df875747cc25f884156aad2abd12b6c46797971342" -dependencies = [ - "libc", - "num_cpus", - "winapi", -] - [[package]] name = "crossbeam-queue" version = "0.3.12" @@ -313,6 +298,12 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + [[package]] name = "flume" version = "0.12.0" @@ -325,10 +316,8 @@ dependencies = [ [[package]] name = "futures-core" version = "0.3.32" -version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" -checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" [[package]] name = "futures-io" @@ -379,12 +368,33 @@ dependencies = [ "slab", ] +[[package]] +name = "generator" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52f04ae4152da20c76fe800fa48659201d5cf627c5149ca0b707b69d7eef6cf9" +dependencies = [ + "cc", + "cfg-if", + "libc", + "log", + "rustversion", + "windows-link", + "windows-result", +] + [[package]] name = "hermit-abi" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.183" @@ -395,7 +405,7 @@ checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" name = "linux-raw-sys" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "lock_api" @@ -407,13 +417,47 @@ dependencies = [ ] [[package]] -name = "num_cpus" -version = "1.17.0" +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "loom" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +checksum = "419e0dc8046cb947daa77eb95ae174acfbddb7673b4151f56d1eed8e93fbfaca" dependencies = [ - "hermit-abi", - "libc", + "cfg-if", + "generator", + "pin-utils", + "scoped-tls", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys", ] [[package]] @@ -440,6 +484,12 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "piper" version = "0.2.5" @@ -483,12 +533,28 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + [[package]] name = "rt-gate" -version = "0.1.3" +version = "0.1.5" dependencies = [ "compio", - "compio-runtime", "smol", "tokio", ] @@ -506,6 +572,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "scoped-tls" version = "1.0.1" @@ -518,6 +590,21 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" version = "1.4.8" @@ -532,7 +619,7 @@ dependencies = [ name = "slab" version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" @@ -589,11 +676,12 @@ dependencies = [ [[package]] name = "synchrony" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "833f3fa2585e125e37cc9f07a0a80c101e243436adf382cdf2b3db8d02fc44e5" +checksum = "e6d5f5d3091c2d998f6ab4c8b495c0d232ad0aecbc1fa9ac52c247a79d497e16" dependencies = [ "futures-util", + "loom", ] [[package]] @@ -602,6 +690,15 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4164c6c316ba9733b0ab021e7f9852c788a4b991b49c25820f1be48e1d41345b" +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + [[package]] name = "tokio" version = "1.50.0" @@ -626,34 +723,51 @@ name = "tracing-core" version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] [[package]] -name = "unicode-ident" -version = "1.0.24" +name = "tracing-log" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] [[package]] -name = "winapi" -version = "0.3.9" +name = "tracing-subscriber" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "unicode-ident" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "valuable" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] name = "windows-link" @@ -661,6 +775,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.61.2" diff --git a/Cargo.toml b/Cargo.toml index 4b89cf5..edd460b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rt-gate" -version = "0.1.3" +version = "0.1.5" edition = "2021" authors = ["Rogerio Araújo "] repository = "https://github.com/ararog/gate" @@ -12,15 +12,17 @@ keywords = ["tasks", "async", "runtime", "wrapper"] publish = true rust-version = "1.64.0" +[package.metadata.docs.rs] +all-features = true + [features] -default = ["compio-rt"] +default = ["tokio-rt"] smol-rt = ["dep:smol"] -tokio-rt = ["dep:tokio"] -compio-rt = ["compio/runtime", "dep:compio-runtime"] +tokio-rt = ["dep:tokio", "tokio/rt-multi-thread"] +#compio-rt = ["compio/runtime"] [dependencies] compio = { version = "0.18.0", optional = true, default-features = false } -compio-runtime = { version = "0.11.0", optional = true, default-features = false } smol = { version = "2.0.2", optional = true, default-features = false } -tokio = { version = "1.50.0", features = ["rt-multi-thread"], default-features = false, optional = true } +tokio = { version = "1.50.0", optional = true, default-features = false } diff --git a/docs/index.md b/docs/index.md index b930870..b4ab76e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,8 +1,8 @@ --- layout: default -title: Gate - The effortless HTTP mock server +title: Gate - A tiny wrapper for async runtimes nav_order: 1 -description: "🧪 The effortless HTTP mock server for seamless API testing" +description: "A tiny wrapper for async runtimes" permalink: / ---
@@ -11,16 +11,7 @@ permalink: / [![Crates.io downloads](https://img.shields.io/crates/d/gate)](https://crates.io/crates/gate) [![crates.io](https://img.shields.io/crates/v/gate?style=flat-square)](https://crates.io/crates/gate) [![Build Status](https://github.com/ararog/gate/actions/workflows/rust.yml/badge.svg?event=push)](https://github.com/ararog/gate/actions/workflows/rust.yml) ![Crates.io MSRV](https://img.shields.io/crates/msrv/gate) [![Documentation](https://docs.rs/gate/badge.svg)](https://docs.rs/gate/latest/gate) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ararog/gate/blob/main/LICENSE.md) [![codecov](https://codecov.io/gh/ararog/gate/graph/badge.svg?token=T0HSBAPVSI)](https://codecov.io/gh/ararog/gate) -**gate** is a powerful yet simple HTTP mock server designed specifically for testing HTTP clients. Built on top of [VeTiS](https://github.com/ararog/vetis), it provides a clean, intuitive API for creating realistic mock endpoints that simulate real-world API behavior, making your testing workflow faster and more reliable. - -## Features - -- **Testing-Focused**: Purpose-built for HTTP client testing scenarios -- **Lightning Fast**: Powered by VeTiS for optimal performance -- **Flexible Runtime**: Choose between Tokio or Smol async runtimes -- **Full Protocol Support**: HTTP/1, HTTP/2, and HTTP/3 compatibility -- **Secure Testing**: Built-in TLS support for HTTPS endpoint testing -- **Minimal Dependencies**: Lightweight footprint for your test suite +**gate** is a tiny wrapper for async runtimes. ## Quick Start @@ -28,98 +19,23 @@ Add to your `Cargo.toml`: ```toml [dependencies] -easyhttpmock = { version = "0.0.9" } +gate = { version = "0.1.3" } ``` Basic usage: ```rust -use http::StatusCode; - -use easyhttpmock::{ - EasyHttpMock, - config::EasyHttpMockConfig, - server::{ - PortGenerator, - adapters::vetis_adapter::{VetisAdapter, VetisAdapterConfig}, - }, -}; - -use deboa::{ - Client, - cert::{Certificate, ContentEncoding}, - request::DeboaRequest, -}; - -use vetis::Response; - -pub const CA_CERT: &[u8] = include_bytes!("../certs/ca.der"); -pub const CA_CERT_PEM: &[u8] = include_bytes!("../certs/ca.crt"); - -pub const SERVER_CERT: &[u8] = include_bytes!("../certs/server.der"); -pub const SERVER_KEY: &[u8] = include_bytes!("../certs/server.key.der"); - -#[tokio::main] -async fn main() -> Result<(), Box> { - let vetis_adapter_config = VetisAdapterConfig::builder() - .interface("0.0.0.0") - .with_random_port() - .cert(Some(SERVER_CERT.to_vec())) - .key(Some(SERVER_KEY.to_vec())) - .ca(Some(CA_CERT.to_vec())) - .build(); - - let config = EasyHttpMockConfig::::builder() - .server_config(vetis_adapter_config) - .build(); - - let mut server = EasyHttpMock::new(config)?; - let result = server - .start(|_| async move { - Ok(Response::new(Full::new(Bytes::from("Hello World")))) - }) - .await; - - result.unwrap_or_else(|err| { - panic!("Failed to start mock server: {}", err); - }); - - let client = Client::builder() - .certificate(deboa::cert::Certificate::from_slice(CA_CERT, ContentEncoding::DER)) - .build(); - - let request = DeboaRequest::get(server.url("/anything"))?.build()?; - - let response = client - .execute(request) - .await?; - - if response.status() == StatusCode::OK { - println!("Request executed successfully"); - } - - server - .stop() - .await?; - - Ok(()) -} + ``` ## Examples -Check out the [examples](./examples.md) for complete examples of how to use EasyHttpMock in your projects. - -## Create project from template - -You can create a new project from the template using `cargo generate`: +Check out the [examples](./examples.md) for complete examples of how to use Gate in your projects. -`cargo generate ararog/easyhttpmock-templates` ## Documentation -- [API Reference](https://docs.rs/easyhttpmock) -- [Migration Guide](./MIGRATION_GUIDE.md) +- [API Reference](https://docs.rs/gate) - [Contributing Guide](./CONTRIBUTING.md) ## License