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 downloadsudo 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
# health
curl -X GET http://localhost:9090/
# hello
curl -X GET http://localhost:9090/healthcheck
# create a short url
curl -X POST http://localhost:9090/shorten -H "Content-Type: application/json" -d '{"url": "https://github.com"}'
# resolve a short code
curl -X GET http://localhost:9090/resolve/4KepjkTTSeeds a single record with a far-future end time.
curl -i -X POST http://localhost:9090/seedThis inserts a suite of tricky date/time rows to help catch regressions:
dt-sentinel-9999-01-01T00:00:00Z→ end_time9999-01-01dt-max-9999-12-31T23:59:59.999999Z→ end_time9999-12-31 23:59:59.999999dt-min-1000-01-01T00:00:00Z→ end_time1000-01-01dt-epoch-1970-01-01T00:00:00Z→ end_time1970-01-01dt-leap-2020-02-29T12:34:56Z→ end_time2020-02-29 12:34:56dt-offset-2023-07-01T18:30:00+05:30→ end_time normalized to local (e.g.,2023-07-01 13:00:00ifloc=Local)dt-now-trunc→ end_time is “now”, truncated to microseconds
Each is tagged with created_by = "keploy.io/dates".
curl -i -X POST http://localhost:9090/seed/datescurl -i "http://localhost:9090/query/by-endtime?ts=9999-12-31T23:59:59.999999Z" curl -i "http://localhost:9090/query/by-endtime?ts=9999-01-01T00:00:00Z"
curl -i http://localhost:9090/query/sentinels
curl -i http://localhost:9090/query/label/dt-leap-2020-02-29T12:34:56Z
curl -i http://localhost:9090/query/dates
> These queries are designed so Keploy can record exact MySQL traffic and later replay it to **catch subtle encoder/decoder regressions** in date/time handling.
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.

# Run the captured testcases
Now that we have our testcase captured, run the test file.
```bash
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:
