Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.8.0 alpha #109

Merged
merged 13 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Deploy to GitHub Pages

on:
# Trigger the workflow every time you push to the `main` branch
# Using a different branch name? Replace `main` with your branch’s name
push:
branches: [ development ]
# Allows you to run this workflow manually from the Actions tab on GitHub.
workflow_dispatch:

# Allow this job to clone the repo and create a page deployment
permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout your repository using git
uses: actions/checkout@v4
- name: Install, build, and upload your site
uses: withastro/action@v2
with:
path: ./docs/website # The root location of your Astro project inside the repository. (optional)

deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
/tools/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
Expand All @@ -13,4 +14,12 @@ Cargo.lock
*.iml

# OSX
.DS_Store
.DS_Store

# LLVM coverage and profiling tool files
*.profraw

# Coverage report files
cobertura.xml
tarpaulin-report.html

15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# Changelog

## Version 0.7.1

- A new [MockServer::reset](https://docs.rs/httpmock/latest/httpmock/struct.MockServer.html#method.reset) method was added that resets a mock server. Thanks for providing the [pull request](https://github.com/alexliesenfeld/httpmock/pull/100) for this feature, [@dax](https://github.com/dax).
## Version 0.8.0

### BREAKING CHANGES
- A new [MockServer::reset](https://docs.rs/httpmock/latest/httpmock/struct.MockServer.html#method.reset) method was added that resets a mock server. Thanks for providing the [pull request](https://github.com/alexliesenfeld/httpmock/pull/100) for this feature, [@dax](https://github.com/dax).
- The default port for standalone server was changed from `5000` to `5050` due to conflicts with system services on macOS.
- [Custom matcher functions](https://docs.rs/httpmock/latest/httpmock/struct.When.html#method.matches) are now closures rather than functions.
- [When::json_body_partial](https://docs.rs/httpmock/0.7.0/httpmock/struct.When.html#method.json_body_partial) was renamed to `json_body_includes`.
- [When::x_www_form_urlencoded_tuple](https://docs.rs/httpmock/0.7.0/httpmock/struct.When.html#method.x_www_form_urlencoded) was renamed to `form_urlencoded_tuple`.
- [When::x_www_form_urlencoded_key_exists](https://docs.rs/httpmock/0.7.0/httpmock/struct.When.html#method.x_www_form_urlencoded) was renamed to `form_urlencoded_key_exists`.

### Improvements
- The algorithm to find the most similar request in case of mock assertion failures has been improved.

## Version 0.7.0

Expand Down
128 changes: 128 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series
of actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
59 changes: 38 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "httpmock"
version = "0.7.0"
version = "0.8.0-alpha.1"
authors = ["Alexander Liesenfeld <alexander.liesenfeld@outlook.com>"]
edition = "2018"
description = "HTTP mocking library for Rust"
Expand All @@ -18,45 +18,62 @@ lazy_static = "1.4"
base64 = "0.22"
regex = "1.10"
log = "0.4"
url = "2.4"
url = "2.5"
stringmetrics = "2"
assert-json-diff = "2.0"
async-trait = "0.1"
async-object-pool = "0.1"
crossbeam-utils = "0.8"
futures-util = "0.3"
similar = "2.3"
levenshtein = "1.0"
similar = "2.6"
form_urlencoded = "1.2"

hyper = { version = "0.14", features = ["server", "http1", "tcp"] }
tokio = { version = "1.33", features = ["sync", "macros", "rt-multi-thread", "signal"] }

isahc = { version = "1.7", optional = true }
basic-cookies = { version = "0.1", optional = true }
colored = { version = "2.0", optional = true }
clap = { version = "4.4", features = ["derive", "env"], optional = true }
thiserror = "1.0"
path-tree = "0.8"
http = "1"
bytes = { version = "1", features = ["serde"] }
hyper = { version = "1.4", features = ["server", "http1", "client"] }
hyper-util = { version = "0.1", features = ["tokio", "server", "http1", "server-auto"] }
http-body-util = "0.1"
tokio = { version = "1.36", features = ["sync", "macros", "rt-multi-thread", "signal"] }
tabwriter = "1.4"
colored = { version = "2.1", optional = true }
clap = { version = "4.5", features = ["derive", "env"], optional = true }
env_logger = { version = "0.11", optional = true }
serde_yaml = { version = "0.9", optional = true }
async-std = { version = "1.12", features = ["attributes", "unstable"] }
headers = { version = "0.4", optional = true }

### TLS / HTTPS / PROXY
rustls = { version = "0.23", default-features = false, features = ["std", "tls12"], optional = true }
rcgen = { version = "0.12", features = ["pem", "x509-parser"], optional = true }
tokio-rustls = { version = "0.26", optional = true }
rustls-pemfile = { version = "2", optional = true }
tls-detect = { version = "0.1", optional = true }
hyper-rustls = { version = "0.27", optional = true }
futures-timer = "3"

[dev-dependencies]
env_logger = "0.11"
tokio-test = "0.4"
quote = "1.0"
actix-rt = "2.9"
colored = "2.0"
ureq = "2.8"

isahc = { version = "1.7", features = ["json"] }
colored = "2.1"
reqwest = { version = "0.12", features = ["blocking", "cookies", "rustls-tls", "rustls-tls-native-roots"] }
syn = { version = "2.0", features = ["full"] }
urlencoding = "2.1.2"

reqwest = "0.11.22"
[features]
default = ["cookies"]
standalone = ["clap", "env_logger", "serde_yaml", "remote"]
color = ["colored"]
cookies = ["basic-cookies"]
remote = ["isahc"]
standalone = ["clap", "env_logger", "record", "http2", "cookies", "remote", "remote-https"] # enables standalone mode
color = ["colored"] # enables colorful output in standalone mode
cookies = ["headers"] # enables support for matching cookies
remote = ["hyper-util/client-legacy", "hyper-util/http2"] # allows to connect to remote mock servers
remote-https = ["remote", "rustls", "hyper-rustls", "hyper-rustls/http2"] # allows to connect to remote mock servers via HTTPS
proxy = ["remote-https", "hyper-util/client-legacy", "hyper-util/http2", "hyper-rustls", "hyper-rustls/http2"] # enables proxy functionality
https = ["rustls", "rcgen", "tokio-rustls", "rustls-pemfile", "rustls/ring", "tls-detect"] # enables httpmock server support for TLS/HTTPS
http2 = ["hyper/http2", "hyper-util/http2"] # enables httpmocks server support for HTTP2
record = ["proxy", "serde_yaml"]
experimental = [] # marker feature for experimental features

[[bin]]
name = "httpmock"
Expand Down
32 changes: 15 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
# ================================================================================
# Builder
# ================================================================================
# First stage: build the application
FROM rust:1.74 as builder
WORKDIR /usr/src/httpmock

COPY Cargo.toml .

COPY src/ ./src/

RUN cargo install --features="standalone" --path .

# ================================================================================
# Runner
# ================================================================================
FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y openssl && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/cargo/bin/httpmock /usr/local/bin/httpmock
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Log level (refer to env_logger crate for more information)
ENV RUST_LOG httpmock=info

# The TCP port on which the mock server will listen to.
ENV HTTPMOCK_PORT 5000
ENV HTTPMOCK_PORT 5050

# Container internal directory path that contains file bases mock specs (YAML-fies).
# ENV HTTPMOCK_MOCK_FILES_DIR /mocks
Expand All @@ -32,6 +20,16 @@ ENV HTTPMOCK_PORT 5000
# Request history limit.
ENV HTTPMOCK_REQUEST_HISTORY_LIMIT 100

WORKDIR /httpmock

COPY Cargo.toml .
# COPY Cargo.lock .

COPY src/ ./src/
COPY certs/ ./certs/

RUN cargo install --all-features --path .

ENTRYPOINT ["httpmock", "--expose"]

EXPOSE ${HTTPMOCK_PORT}
Loading
Loading