A sample url shortener app to test Keploy integration capabilities

Example URL Shortener

A sample url shortener app to test Keploy integration capabilities

Installation

git clone https://github.com/keploy/example-url-shortener
cd example-url-shortener
go mod tidy

The App also requires mongo

docker container run -it  -p 27017:27017 mongo

Add Keploy SDK

To add the keploy the SDK we need to wrap the dependencies of the url-shortner app, here, dynamodb client and webgo router.

See complete instructions to integrate Keploy Go SDK at keploy/go-sdk

For demo purpose, checkout to the keploy branch which has the integrations done already.

git checkout keploy 

Now enter your API key in the keploy initialization method in main.go.

kply := keploy.NewApp("url-shortener", "<API_KEY>", "https://api.keploy.io", host, port)

Capture mode

To capture testcases, set the KEPLOY_SDK_MODE environment variable to capture and run the app

export KEPLOY_SDK_MODE="capture" && go run generator.go main.go

Let's capture some traffic by making some API calls. You can use Postman, Hoppscotch, or simply curl

  1. Generate shortned url
curl --request POST \
  --url http://localhost:8080/url \
  --header 'content-type: application/json' \
  --data '{
  "url": "https://google.com"
}'

this will return the shortned url

{
  "data": {
    "url": "http://localhost:8080/Lhr4BWAi"
  },
  "status": 200
}
  1. Redirect to original url from shortened url
curl --request GET \
  --url http://localhost:8080/Lhr4BWAi

or by querying through the browser http://localhost:8080/Lhr4BWAi

Now both these API calls were captured as a testcase and should be visible on the Keploy console. If you're using Keploy cloud, open Console.

You should be seeing an app named url-shortener with the test cases we just captured.

testcases

Now, let's see the magic! 🪄 💫

Test mode

Now that we have our testcase captured. Shut down your mongo docker container. 😐

Change the KEPLOY_SDK_MODE to test

export KEPLOY_SDK_MODE="test" && go run generator.go main.go

Run the application again!

All the test-cases will be downloaded locally and run with the app.

Guess what!?

MongoDB calls are mocked while running these test cases!

So no need to setup dependencies like mongoDB, web-go locally during testing.

The application thinks it's talking to mongoDB 😄

Go to the Keploy Console/testruns to get deeper insights on what testcases ran, what failed.

testruns testruns testruns

If you are using other dependencies, feel free to create an issue, we'll add the support asap!

Similar Resources

Cfurlshort - Url Shortener service with golang

Url Shortener This respository contains the code for my url shortener service. D

Jan 26, 2022

Goshort - Just another simple url shortener to use with curl

qnd.be Just another simple url shortener to use with curl. Kinda like 0x0.st. Ju

Jan 29, 2022

OMUS - One More URL Shortener

OMUS OMUS - One More URL Shortener; For now - planned only API. Functions: Gener

Feb 12, 2022

Short url backend - Go musthave shortener tpl

go-musthave-shortener-tpl Шаблон репозитория для практического трека «Go в веб-р

Feb 15, 2022

The 'Scalable' URL shortener

Chinnaswamy The 'Scalable' URL shortener Running tests To run end to end tests: CHINNASWAMY_TEST_HOST="host:port" go test -count=1 ./integration_tes

Dec 2, 2022

urlhunter is a recon tool that allows searching on URLs that are exposed via shortener services such as bit.ly and goo.gl.

urlhunter is a recon tool that allows searching on URLs that are exposed via shortener services such as bit.ly and goo.gl.

a recon tool that allows searching on URLs that are exposed via shortener services

Jan 7, 2023

Test-swaggo - Test swaggo with redis

Requirements Go 1.16 MySql Redis Development Install Dependencies go mod downloa

Jan 29, 2022

記帳-PWA-web-app (Bookkeeping-PWA-web-app)

記帳-PWA-web-app (Bookkeeping-PWA-web-app)

GoKeep (bookkeeping web app) 記帳-PWA-web-app (Bookkeeping-PWA-web-app) demo link : https://bookkepping.herokuapp.com/ 測試用帳密 : tester002 , tester002 (亦可

Jan 31, 2022

License-API - Basic license based authentication API with discord account integration

License-API Basic license based authentication API with discord account integrat

Feb 18, 2022
Comments
  • Make the URL non deterministic

    Make the URL non deterministic

    To demonstrate how we remove noise, we should make the generated URLs random instead of hashes so that they are different every time for the same input URL. Given this behavior, Keploy should be able to mark it as a noisy field.

  • Removed sha256of function, made URL randomly generated.

    Removed sha256of function, made URL randomly generated.

    In reference to the only open issue currently, #3, I removed the sha256of function and instead made the generated URL non-deterministic instead so that the URL is different every time for the same input URL.

  • update documentation for versioned packages and include import statements

    update documentation for versioned packages and include import statements

    • import statements for the library that keploy is integrated with are missing this needs to be included
    • update all versioned package names to the versions being used i.e http://github.com/keploy/go-sdk/integrations/kgin should be changed to http://github.com/keploy/go-sdk/integrations/kgin/v1
A URL shortener using http://is.gd/ and the Go programming language (http://golang.org/)

goisgd A simple command line URL shortener using http://is.gd/. Getting the Code go get github.com/NickPresta/GoURLShortener Usage Import this librar

Apr 6, 2022
a url shortener made using go and redis

__ | |--.--.--.----.-----. .-----.-----. | <| | | _|-- __|__| _ | _ | |__|__|_____|__| |_____|__|___

Dec 10, 2020
urlsh is URL shortener application built on Go language.
urlsh is URL shortener application built on Go language.

GOlang URL shortener service with UI, API, Cache, Hits Counter and forwarder using postgres and redis in backend, bulma in frontend

Dec 11, 2022
A barebones URL Shortener implementation in Go using Gin and MySQL. Also features a basic frontend.

URL Shortener in Go This is a barebones URL Shortener implementation in Go using the Gin web framework and MySQL. Also features a basic frontend. Loca

Dec 22, 2021
Go URL shortener

Golang Short URL To build the short link engine by Go. Development Environment: Ubuntu 20.04 Go 1.17.1 Requirement Console app, receive “URL” from any

Nov 4, 2021
A simple URL shortener application.

url-shortener A simple URL shortener application. Features The service supports 2 data stores (in-memory and PostgreSQL). The -db parameter is used to

Dec 9, 2021
Yandex practicum go url shortener service

go-musthave-shortener-tpl Шаблон репозитория для практического трека «Go в веб-р

Feb 26, 2022
Url Shortener Api For Golang

Url Shortener Api Using Go Endpoints Get and redirect to long url GET: "/:id" Cr

May 29, 2022
Simple URL shortener written in Golang

Alviss Introduction Simple URL shortener project, written in Golang. Setup and r

Aug 25, 2022
API from AnonURL website, an anonymous URL shortener

API from AnonURL website, an anonymous URL shortener

Jan 23, 2022