A sample url shortener app to test Keploy integration capabilities

Overview

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!

You might also like...
Cfurlshort - Url Shortener service with golang

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

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

OMUS - One More URL Shortener

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

Short url backend - Go musthave shortener tpl

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

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

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

Test-swaggo - Test swaggo with redis

Requirements Go 1.16 MySql Redis Development Install Dependencies go mod downloa

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

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

記帳-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 (亦可

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.

    opened by slayerjain 2
  • 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.

    opened by petergeorgas 1
  • 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
    opened by skant7 0
Owner
null
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

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

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

André Kelpe 76 Dec 10, 2020
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

Jitendra Adhikari 115 Sep 14, 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

Shreyas Gupta 6 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

Siong-Ui Te (戴上為) 0 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

Demid Fedorov 0 Dec 9, 2021
Yandex practicum go url shortener service

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

Dindon 0 Feb 26, 2022
Url Shortener Api For Golang

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

Lutfi Andriyanto 1 May 29, 2022
Simple URL shortener written in Golang

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

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

API from AnonURL website, an anonymous URL shortener

null 0 Jan 23, 2022