Skip to content

Commit

Permalink
feat: added new sample apps
Browse files Browse the repository at this point in the history
Signed-off-by: Animesh <[email protected]>
  • Loading branch information
Sonichigo authored and actions-user committed Sep 21, 2023
1 parent 7835ff0 commit 0217bd5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 18 deletions.
26 changes: 20 additions & 6 deletions versioned_docs/version-2.0.0/quickstart/samples-echo.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ keyword:
- API Test generator
- Auto Testcase generation
---

# URL Shortener

A sample url shortener app to test Keploy integration capabilities using [Echo](https://echo.labstack.com/) and PostgreSQL.
A sample url shortener app to test Keploy integration capabilities using [Echo](https://echo.labstack.com/) and PostgreSQL.

## Installation Setup

Expand Down Expand Up @@ -48,14 +49,15 @@ sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy

</details>

### Start Postgres Instance
### Start Postgres Instance

Using the docker-compose file we will start our postgres instance:-

```bash
# Start Postgres
docker-compose up -d
```

### Capture the Testcases

> **Since, we are on the local machine the Postgres Host will be `localhost`.**
Expand All @@ -74,7 +76,6 @@ sudo -E keploy record -c "./echo-psql-url-shortener"

Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.


### Generate testcases

To generate testcases we just need to make some API calls. You can use [Postman](https://www.postman.com/), [Hoppscotch](https://hoppscotch.io/), or simply `curl`
Expand All @@ -99,9 +100,10 @@ this will return the shortened url. The ts would automatically be ignored during
}
```

#### Redirect to original URL from shortened URL
#### Redirect to original URL from shortened URL

1. By using Curl Command

```bash
curl --request GET \
--url http://localhost:8082/GuwHCgoQ
Expand All @@ -117,7 +119,7 @@ Now, let's see the magic! ✨💫

## Run the Testcases

Now that we have our testcase captured, we will add `ts` to noise field in `test-*.yaml` files.
Now that we have our testcase captured, we will add `ts` to noise field in `test-*.yaml` files.

**1. On line 32 we will add "`- body.ts`" under the "`header.data`".**

Expand All @@ -138,19 +140,23 @@ So no need to setup fake database/apis like Postgres or write mocks for them. Ke
Keploy can be used on Linux & Windows through Docker, and on MacOS by the help of [Colima](https://docs.keploy.io/docs/server/macos/installation/#using-colima)

## Create Keploy Alias

To establish a network for your application using Keploy on Docker, follow these steps.

If you're using a docker-compose network, replace keploy-network with your app's `docker_compose_network_name` below.

```shell
alias keploy='sudo docker run --pull always --name keploy-v2 -p 16789:16789 --privileged --pid=host -it -v "$(pwd)":/files -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm ghcr.io/keploy/keploy'
```

## Let's start the MongoDB Instance

Using the docker-compose file we will start our mongodb instance:-

```zsh
docker-compose up -d
```

> Since we are using docker to run the application, we need to update the `postgres` host on line 28 in `main.go`, update the host to `echo-sql-postgres-1`.
Now, we will create the docker image of our application:-
Expand All @@ -168,9 +174,11 @@ keploy record -c "docker run -p 8082:8082 --rm --name echoSqlApp --network keplo
![Testcase](../../../static/img/testcase-echo.png?raw=true)

### Generate testcases

To genereate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl

1. Generate shortned url

```bash
curl --request POST \
--url http://localhost:8082/url \
Expand All @@ -179,6 +187,7 @@ curl --request POST \
"url": "https://google.com"
}'
```

this will return the shortened url.

```json
Expand All @@ -187,22 +196,27 @@ this will return the shortened url.
"url": "http://localhost:8082/Lhr4BWAi"
}
```

2. Redirect to original url from shòrtened url

```
curl --request GET \
--url http://localhost:8082/Lhr4BWAi
or by querying through the browser http://localhost:8082/Lhr4BWAi
or by querying through the browser http://localhost:8082/Lhr4BWAi
```

Now, let's see the magic! 🪄💫

Now both these API calls were captured as a testcase and should be visible on the Keploy CLI. You should be seeing an app named keploy folder with the test cases we just captured and data mocks created.

## Run the captured testcases

Now that we have our testcase captured, run the test file.

```zsh
keploy test -c "sudo docker run -p 8082:8082 --rm --net keploy-network --name echoSqlApp echo-app:1.0 --rm echoSqlApp" --delay 10
```

So no need to setup dependencies like mongoDB, web-go locally or write mocks for your testing.

The application thinks it's talking to mongoDB 😄
Expand Down
38 changes: 27 additions & 11 deletions versioned_docs/version-2.0.0/quickstart/samples-mux.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ keyword:
- API Test generator
- Auto Testcase generation
---

# Product Catelog

A sample url shortener app to test Keploy integration capabilities

## Installation Setup
Expand Down Expand Up @@ -47,14 +49,15 @@ sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy

</details>

### Start Postgres Instance
### Start Postgres Instance

Using the docker-compose file we will start our postgres instance:-

```bash
# Start Postgres
docker-compose up -d
```

### Capture the Testcases

> **Since, we are on the local machine the Postgres Host will be `localhost`.**
Expand Down Expand Up @@ -84,11 +87,13 @@ curl --request POST \
--url http://localhost:8010/product \
--header 'content-type: application/json' \
--data '{
"name":"Bubbles",
"name":"Bubbles",
"price": 123
}'
```
this will return the response.

this will return the response.

```
{
"id": 1,
Expand All @@ -98,15 +103,17 @@ this will return the response.
```

#### 2. Redirect to original url from shortened url

1. By using Curl Command

```bash
curl --request GET \
--url http://localhost:8010/products
```

2. By querying through the browser `http://localhost:8010/products`

Now both these API calls were captured as editable testcases and written to ``keploy/tests folder``. The keploy directory would also have `mocks` files that contains all the outputs of postgres operations.
Now both these API calls were captured as editable testcases and written to `keploy/tests folder`. The keploy directory would also have `mocks` files that contains all the outputs of postgres operations.

![Testcase](../../../static/img/testcase.png?raw=true)

Expand All @@ -131,22 +138,25 @@ So no need to setup fake database/apis like Postgres or write mocks for them. Ke
Keploy can be used on Linux & Windows through Docker, and on MacOS by the help of [Colima](https://docs.keploy.io/docs/server/macos/installation/#using-colima)

## Create Keploy Alias

To establish a network for your application using Keploy on Docker, follow these steps.

If you're using a docker-compose network, replace keploy-network with your app's `docker_compose_network_name` below.

```shell
alias keploy='sudo docker run --pull always --name keploy-v2 -p 16789:16789 --privileged --pid=host -it -v "$(pwd)":/files -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm ghcr.io/keploy/keploy'
```

## Let's start the MongoDB Instance

Using the docker-compose file we will start our mongodb instance:-

```shell
docker-compose up -d
```

> Since we are using docker to run the application, we need to update the `postgres` host on line 10 in `main.go`, update the host to `mux-sql-postgres-1`.
Now, we will create the docker image of our application:-
> Now, we will create the docker image of our application:-
```shell
docker build -t mux-app:1.0 .
Expand All @@ -161,44 +171,50 @@ keploy record -c "docker run -p 8010:8010 --rm --name muxSqlApp --network keploy
![Testcase](../../../static/img/testcase.png?raw=true)

### Generate testcases

To genereate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl

```bash
curl --request POST \
--url http://localhost:8010/product \
--header 'content-type: application/json' \
--data '{
"name":"Bubbles",
"name":"Bubbles",
"price": 123
}'
```
this will return the response.

this will return the response.

```json
{
"id": 1,
"name": "Bubbles",
"price": 123
"id": 1,
"name": "Bubbles",
"price": 123
}
```

#### 2. Redirect to original url from shortened url

1. By using Curl Command

```bash
curl --request GET \
--url http://localhost:8010/products
```

2. By querying through the browser `http://localhost:8010/products`

Now both these API calls were captured as editable testcases and written to ``keploy/tests folder``. The keploy directory would also have `mocks` files that contains all the outputs of postgres operations.
Now both these API calls were captured as editable testcases and written to `keploy/tests folder`. The keploy directory would also have `mocks` files that contains all the outputs of postgres operations.

## Run the captured testcases

Now that we have our testcase captured, run the test file.

```shell
keploy test -c "sudo docker run -p 8010:8010 --net keploy-network --rm --name muxSqlApp mux-app:1.0" --delay 10
```

So no need to setup dependencies like mongoDB, web-go locally or write mocks for your testing.

The application thinks it's talking to mongoDB 😄
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ If you're running an older build, or just prefer not to use the install command
Once installed download and Install "Keploy Binary" :

```zsh
=======
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp

sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
Expand Down

0 comments on commit 0217bd5

Please sign in to comment.