Skip to content

Commit

Permalink
updated echo-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 6, 2024
1 parent 6238f95 commit 18d7ec0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
20 changes: 10 additions & 10 deletions echo-mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ A simple Go-based URL shortener application.

# Prerequisites

1. Golang: [How to install Golang](https://go.dev/doc/install)
1. Golang: [Install Golang](https://go.dev/doc/install)
2. Docker: [Install Docker](https://docs.docker.com/engine/install/)

# Setting up the project

Clone the repository and download the necessary Go modules by running the following commands:

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

# Running app
Expand All @@ -23,7 +23,7 @@ go mod download
Use Docker to run a MySQL container:

```bash
sudo docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=uss -p 3306:3306 --rm mysql:latest
sudo docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=uss -p 3306:3306 --rm mysql:latest
```

## Build the application
Expand All @@ -39,33 +39,33 @@ Compile the application with:
To capture test cases, run the application in record mode:

```bash
sudo -E env PATH=$PATH oss record -c "./echo-mysql"
sudo -E env PATH=$PATH oss record -c "./echo-mysql"
```

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

1. Root Endpoint:

```bash
-> curl -X GET http://localhost:9090/
curl -X GET http://localhost:9090/
```

2. Health Check:

```bash
-> curl -X GET http://localhost:9090/healthcheck
curl -X GET http://localhost:9090/healthcheck
```

3. Short URL:

```bash
-> curl -X POST http://localhost:9090/shorten -H "Content-Type: application/json" -d '{"url": "https://github.com"}'
curl -X POST http://localhost:9090/shorten -H "Content-Type: application/json" -d '{"url": "https://github.com"}'
```

4. Resolve short code:

```bash
-> curl -X GET http://localhost:9090/resolve/4KepjkTT
curl -X GET http://localhost:9090/resolve/4KepjkTT
```

Captured API calls will appear as test cases in the Keploy CLI. A new directory named keploy will contain the recorded test cases and data mocks.
Expand All @@ -79,7 +79,7 @@ Captured API calls will appear as test cases in the Keploy CLI. A new directory
Once the test cases are captured, you can run them with the following command:

```bash
sudo -E env PATH=$PATH oss test -c "./echo-mysql" --delay 20
sudo -E env PATH=$PATH oss test -c "./echo-mysql" --delay 20
```

## Explanation
Expand Down
29 changes: 15 additions & 14 deletions echo-sql/README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
# 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
## Installation and Setup

### 1. Clone the Repository

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

## Installation Keploy
### 2. Install Keploy

Install keploy via one-click:-
Install Keploy with a one-liner command:

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

### Start Postgres Instance
## Setting up PostgreSQL

### Start Postgres Instance

Using the docker-compose file we will start our postgres instance ( use `podman-compose` if you are using RHEL based distribution ):-
Start the PostgreSQL instance using the provided docker-compose file (use podman-compose for RHEL-based distributions):

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

If there is an error saying keploy-network could not be found. Use the following command to create the docker network
If you encounter an error about the keploy-network, create the Docker network manually:

```bash
docker network create keploy-network
```


### Update the Host

> **Since we have setup our sample-app natively, we need to update the Postgres host on line 27, in `main.go`, from `postgresDb` to `localhost`.**
### Capture the testcases
## Capture the testcases

Now, we will create the binary of our application:-

Expand All @@ -53,8 +55,7 @@ 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
## 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 @@ -78,9 +79,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 @@ -102,7 +104,6 @@ Now that we have our testcase captured, we will add `ts` to noise field in `test

![EliminateNoise](https://github.com/aswinbennyofficial/samples-go/assets/110408942/2b50d994-3418-4f7b-9f95-5bc1acd8ecf9)


Now let's run the test mode (in the echo-sql directory, not the Keploy directory).

```shell
Expand Down

0 comments on commit 18d7ec0

Please sign in to comment.