-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
19,501 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
.parcel-cache/ | ||
.vscode/ | ||
build/ | ||
docs/.vuepress/dist/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
.vscode/ | ||
build/ | ||
coverage/ | ||
docs/.vuepress/dist/ | ||
node_modules/ | ||
sessions/ | ||
smocker | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Dependencies | ||
/node_modules | ||
|
||
# Production | ||
/build | ||
|
||
# Generated files | ||
.docusaurus | ||
.cache-loader | ||
|
||
# Misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: [require.resolve("@docusaurus/core/lib/babel/preset")], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"label": "Guide", | ||
"position": 1, | ||
"link": { | ||
"type": "generated-index" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
--- | ||
sidebar_position: 3 | ||
--- | ||
|
||
# Getting Started | ||
|
||
Smocker exposes two ports: | ||
|
||
- `8080` is the mock server port. It will expose the routes you register through the configuration port. | ||
- `8081` is the configuration port. It's the port you will use to register new mocks. This port also exposes a user interface. | ||
|
||
To get a better understanding of how Smocker works, let's open its user interface on the browser. With the default configuration, it will be available on [localhost:8081](http://localhost:8081/) | ||
|
||
 | ||
|
||
If you take a look at the sidebar on the left, you can see a list of sessions with one selected element. | ||
|
||
 | ||
|
||
By default, Smocker will automatically create a **session** on the first call trying to retrieve **history** or **mocks**. | ||
But you can also create one using the [API](/docs/technical-documentation/api#start-session). | ||
Smocker shows the history of the calls made to the mock server for the selected session. As we just started it, nothing is displayed yet. | ||
|
||
Let's see how Smocker reacts when we try to call a non existing route. Run the following command in a terminal: | ||
|
||
<details> | ||
<summary><code>curl -i localhost:8080/hello/world</code></summary> | ||
|
||
``` | ||
HTTP/1.1 666 status code 666 | ||
Content-Type: application/json; charset=UTF-8 | ||
Date: Wed, 29 Jan 2020 17:25:31 GMT | ||
Content-Length: 206 | ||
{"message":"No mock found matching the request","request":{"path":"/hello/world","method":"GET","body":"","headers":{"Accept":["*/*"],"User-Agent":["curl/7.54.0"]},"date":"2020-01-29T17:25:31.956225978Z"}} | ||
``` | ||
|
||
</details> | ||
|
||
If you refresh Smocker's user interface, you will see that it now displays an entry in the history: | ||
|
||
 | ||
|
||
Let's look closer at the call: | ||
|
||
- on the left, you can see all the details of the request you made: method `GET`, path `/hello/world`, and headers, | ||
- on the right, you can see the response of Smocker: error code `666`, and informations regarding the error. | ||
|
||
 | ||
|
||
:::note | ||
Smocker reserves the non HTTP status codes from `600` to `699`. This is because we need an out of protocol way to report Smocker errors, which are different from the standard protocol errors. The explicit list of Smocker custom errors is available [here](/docs/technical-documentation/errors). | ||
::: | ||
|
||
To register our first mock, we will use the user interface. Switch to the "Mocks" page and click on the "Add Mock" button. | ||
|
||
 | ||
|
||
 | ||
|
||
Mocks are defined using the YAML format. Register the following mock: | ||
|
||
```yml | ||
- request: | ||
method: GET | ||
path: /hello/world | ||
response: | ||
headers: | ||
Content-Type: application/json | ||
body: > | ||
{ | ||
"hello": "Hello, World!" | ||
} | ||
``` | ||
This mock simply states that when an HTTP `GET` call is made on the `/hello/world` path, the mock server must return a basic JSON document. | ||
|
||
Now, execute the previous call one more time: | ||
|
||
<details> | ||
<summary><code>curl -i localhost:8080/hello/world</code></summary> | ||
|
||
``` | ||
HTTP/1.1 200 OK | ||
Content-Type: application/json | ||
Date: Wed, 29 Jan 2020 17:40:52 GMT | ||
Content-Length: 30 | ||
|
||
{ | ||
"hello": "Hello, World!" | ||
} | ||
``` | ||
</details> | ||
Once you refresh the user interface, you should notice that this last call is present in the history and that Smocker replied with the response we declared instead of an error! | ||
 | ||
You can also visualize call history as a **sequence diagram** by clicking on the `visualize` button on the top right of the page. | ||
 | ||
This covers the basic usage of Smocker, but it was just the beginning! Smocker covers many more topics: | ||
- advanced filters, | ||
- automation, | ||
- dynamic calls, | ||
- proxies, | ||
- contexts, | ||
- and everything you might need to mock your whole environment! | ||
For more details and explanations than just a **Hello World**, we invite you to check the [Real Life Usage](./real-life) section. | ||
And for advanced mocks you can check the [Mock Definition](/docs/technical-documentation/mock-definition) documentation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
sidebar_position: 2 | ||
--- | ||
|
||
# Installation | ||
|
||
Smocker can be installed either with [Docker](https://www.docker.com/) or manually on any Linux system, depending on your needs. | ||
|
||
## With Docker | ||
|
||
```sh | ||
docker run -d \ | ||
--restart=always \ | ||
-p 8080:8080 \ | ||
-p 8081:8081 \ | ||
--name smocker \ | ||
thiht/smocker | ||
``` | ||
|
||
or with TLS enabled: | ||
|
||
```sh | ||
docker run -d \ | ||
--restart=always \ | ||
-p 44300:8080 \ | ||
-p 44301:8081 \ | ||
-e SMOCKER_TLS_ENABLE=true \ | ||
-v /path/to/your/cert.pem:/etc/smocker/tls/certs/cert.pem:ro \ | ||
-v /path/to/your/key.pem:/etc/smocker/tls/private/key.pem:ro \ | ||
--name smocker \ | ||
thiht/smocker | ||
``` | ||
|
||
## Manual Deployment | ||
|
||
:::note | ||
The official binaries are currently built for Linux only. This is not a hard limit though, as the source code should be fully compatible with most of the standard platforms. | ||
::: | ||
|
||
```sh | ||
# This will be the deployment folder for the Smocker instance | ||
mkdir -p /opt/smocker && cd /opt/smocker | ||
wget -P /tmp https://github.com/Thiht/smocker/releases/latest/download/smocker.tar.gz | ||
tar xf /tmp/smocker.tar.gz | ||
rm /tmp/smocker.tar.gz | ||
|
||
nohup ./smocker -mock-server-listen-port=8080 -config-listen-port=8081 & | ||
|
||
# Or with TLS | ||
|
||
# The certificate is expected in /etc/smocker/tls/certs/ by default | ||
# You can override it with -tls-cert-file and -tls-private-key-file | ||
nohup ./smocker -mock-server-listen-port=44300 -config-listen-port=44301 -tls-enable & | ||
``` | ||
|
||
## Healthcheck | ||
|
||
To check that Smocker started successfully, just run the following command: | ||
|
||
```sh | ||
curl localhost:8081/version | ||
``` | ||
|
||
or with TLS enabled: | ||
|
||
```sh | ||
curl https://localhost:44301/version | ||
|
||
# Or if you use a self signed certificate | ||
curl -k https://localhost:44301/version | ||
``` |
Oops, something went wrong.