Skip to content

Latest commit

 

History

History

echo-mysql

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

echo-mysql

A simple golang based url shortner

Requirments to run

  1. Golang How to install Golang
  2. Docker How to install Docker?

Setting up the project

Run the following commands to clone the repository and download the necessary Go modules

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

Running app

Let's start the MySql Instance

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

Build the application

 go build -o echo-mysql . 

Capture the Testcases

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:
-> curl -X GET http://localhost:9090/
  1. Health Check:
-> curl -X GET http://localhost:9090/healthcheck
  1. Short URL:
-> curl -X POST http://localhost:9090/shorten -H "Content-Type: application/json" -d '{"url": "https://github.com"}'
  1. Resolve short code:
-> curl -X GET http://localhost:9090/resolve/4KepjkTT

Now both these API calls were captured as a testcase and should be visible on the Keploy CLI. You should be seeing an app named keploy folder with the test cases we just captured and data mocks created.

alt text

Run the captured testcases

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

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

So no need to setup dependencies like MySQL, web-go locally or write mocks for your testing.

oss test runs the test cases captured in the previous step. It replays the captured API calls against the application to verify its behavior.

The application thinks it's talking to MySQL 😄

We will get output something like this:

alt text