Skip to content

Latest commit

 

History

History

README.md

FastHttp-Postgres

A sample application that get, create, update, and delete the data of a user in the database: -

Start Users-Profile sample application

git clone https://github.com/keploy/samples-go && cd fasthttp-postgres

Installation

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

Keploy can be used on Linux, Windows and MacOS through Docker.

Note: To run Keploy on MacOS through Docker the version must be 4.25.2 or above.

Option 1: Run with Docker

Capture testcases:

keploy record -c "docker compose up" --container-name=fasthttp_app
To genereate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl: -
1. Post Requests
curl -X POST -H "Content-Type: application/json" -d '{"name":"Author Name"}' http://localhost:8080/authors
curl -X POST -H "Content-Type: application/json" -d '{"title":"Book Title","author_id":1}' http://localhost:8080/books
2. Get Requests
curl -i http://localhost:8080/books

Keploy Testcases

Run captured tests:

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

keploy test -c "docker compose up" --container-name=fasthttp_app --delay 10

alt text

Option 2: Run Without Docker

Note: This application requires the following database environment variables to be set in order to run correctly.

Create a .env file in this directory with the following values:

DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=password
DB_NAME=db

Start the Postgres container:

docker compose up -d postgres

Build the Application

go build -o app

Capture testcases:

keploy record -c "./app"

Note: The server would be running on http://localhost:8080

To genereate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl: -
1. Post Requests
curl -X POST -H "Content-Type: application/json" -d '{"name":"Author Name"}' http://localhost:8080/authors
curl -X POST -H "Content-Type: application/json" -d '{"title":"Book Title","author_id":1}' http://localhost:8080/books
2. Get Requests
curl -i http://localhost:8080/books

Keploy Testcases

Run captured tests

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

keploy test -c "./app" --delay 10

alt text

Voila! Our testcases have passed🥳 . We can also notice that by capturing just few API calls we got around 88.5% of aggregated coverage with keploy generated testcases

If you like the sample application, Don't forget to star us ✨