Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Go-JWT

A sample app

Installation Setup

git clone https://github.com/keploy/samples-go.git && cd samples-go/go-jwt
go mod download

Installation Keploy

Install keploy via one-click:-

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

Start the Postgres Database

docker compose up -d db

Capture the Testcases

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

go build .

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

sudo -E keploy record -c "./go-jwt"

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 genereate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl

  1. Generate shortned url
curl --request GET \
      --url http://localhost:8000/health \
      --header 'Accept: */*' \
      --header 'Host: localhost:8000' \
      --header 'User-Agent: curl/7.81.0' 

this will return the response.

{"status": "healthy"}
  1. Fetch the Products
curl --request GET \
      --url http://localhost:8000/generate-token?expiry=15 \
      --header 'Host: localhost:8000' \
      --header 'User-Agent: curl/7.81.0' \
      --header 'Accept: */*' 

we will get output:

{"token":"<your_jwt_token>"}
  1. Fetch a single product
curl --request GET \
      --url http://localhost:8000/check-token?token=<your_jwt_token> \
      --header 'Accept: */*' \
      --header 'Host: localhost:8000' \
      --header 'User-Agent: curl/7.81.0' 

we will get output:-

{"username" : "example_user"}

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.

Testcase

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

Run captured testcases

sudo -E keploy test -c "./go-jwt" --delay 10

Once done, you can see the Test Runs on the Keploy server, like this:

Testrun