Skip to content

Commit

Permalink
updated mux-sql readme
Browse files Browse the repository at this point in the history
Signed-off-by: Swapnoneel Saha <[email protected]>
  • Loading branch information
Swpn0neel committed Dec 15, 2024
1 parent 5eb6f19 commit 788154b
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions mux-sql/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
# Product Catelog
A sample url shortener app to test Keploy integration capabilities
# Product Catalog

A sample URL shortener application to test Keploy's integration capabilities.

## Installation Setup

Clone the repository and install dependencies:

```bash
git clone https://github.com/keploy/samples-go.git && cd samples-go/mux-sql
go mod download
```

## Installation Keploy

Install keploy via one-click:-

```sh
curl --silent -O -L https://keploy.io/install.sh && source install.sh
```

### Start Postgres Instance
## Start Postgres Instance

Using the docker-compose file we will start our postgres instance:-
Use the provided `docker-compose` file to start a PostgreSQL instance:

```bash
docker-compose up -d postgres
Expand All @@ -27,15 +31,19 @@ docker-compose up -d postgres

> **Since we have setup our sample-app natively set the host to `localhost` on line 10.**
### Capture the Testcases
## Capture the Testcases

Now, we will create the binary of our application:-
### Build the Application Binary

Generate the binary for the application:

```zsh
go build -cover
```

Once we have our binary file ready,this command will start the recording of API calls using ebpf:-
### Record API Calls

Use the Keploy `record` command to start capturing API calls via `eBPF`:

```shell
sudo -E keploy record -c "./test-app-product-catelog"
Expand All @@ -54,11 +62,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 @@ -68,6 +78,7 @@ this will return the response.
```

2. Fetch the Products

```bash
curl --request GET \
--url http://localhost:8010/products
Expand All @@ -76,21 +87,24 @@ curl --request GET \
we will get output:

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

3. Fetch a single product

```sh
````sh
curl --request GET \
--url http://localhost:8010/product/1

we will get output:-
```json
{"id":1,"name":"Bubbles","price":123}
```
````
Now, since 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, since 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](./img/testcase.png?raw=true)
Expand All @@ -115,18 +129,19 @@ With the three API calls that we made, we got around `55.6%` of coverage
## Create Unit Testcase with Keploy
### Prequiste
AI model API_KEY to use:
- OpenAI's GPT-4o.
- Alternative LLMs via [litellm](https://github.com/BerriAI/litellm?tab=readme-ov-file#quick-start-proxy---cli).
### Setup
### Setup Dependencies
Download Cobertura formatted coverage report dependencies.
Install dependencies for generating Cobertura-formatted coverage reports:
```bash
go install github.com/axw/gocov/[email protected]
go install github.com/AlekSi/[email protected]
go install github.com/AlekSi/[email protected]
```
Get API key from [OpenAI](https://platform.openai.com/) or API Key from other LLM
Expand All @@ -137,11 +152,12 @@ export API_KEY=<LLM_MODEL_API_KEY>
### Generate Unit tests
Let's check the current code coverage of out application : -
Let's check the current code coverage of out application : -
```bash
go test -v ./... -coverprofile=coverage.out && gocov convert coverage.out | gocov-xml > coverage.xml
```

We got around 44.1% of code coverage.

![Go Test](./img/mux-utg.png?raw=true)
Expand All @@ -154,4 +170,4 @@ keploy gen --sourceFilePath="app.go" --testFilePath="app_test.go" --testCommand=
With the above command, Keploy will generate new testcases in the our `app_test.go` can increase code coverage upto 70%.
![Keploy Mux UTG](./img/mux-utg-codecov.png?raw=true)
![Keploy Mux UTG](./img/mux-utg-codecov.png?raw=true)

0 comments on commit 788154b

Please sign in to comment.