Giter Site home page Giter Site logo

example-url-shortener's Introduction

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!

example-url-shortener's People

Contributors

nehagup avatar slayerjain avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.