A simple golang based url shortner
- Golang How to install Golang
- Docker How to install Docker?
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
sudo docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=uss -p 3306:3306 --rm mysql:latest
go build -o 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
- Root Endpoint:
-> curl -X GET http://localhost:9090/
- Health Check:
-> curl -X GET http://localhost:9090/healthcheck
- Short URL:
-> curl -X POST http://localhost:9090/shorten -H "Content-Type: application/json" -d '{"url": "https://github.com"}'
- 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.
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: