go-jwt

command module
v0.0.0-...-3bce0bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

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 \
      --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

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL