Giter VIP home page Giter VIP logo

devpod-keploy's Introduction

MUX-SQL

This is a sample application that uses the gorilla/mux router and Postgres for database operations. The application is a simple product catalog that allows you to add products, fetch all products, and fetch a single product.

Installation Setup

git clone https://github.com/keploy/samples-go.git && cd samples-go/mux-sql
go mod download

Installation Keploy

Install keploy via one-click:-

curl --silent -O -L https://keploy.io/install.sh && source install.sh

Start Postgres Instance

Using the docker-compose file we will start our postgres instance:-

# Start Postgres
docker-compose up -d postgres

Update the Host

Since we have setup our sample-app natively set the host to localhost on line 10.

Capture the Testcases

Now, we will create the binary of our application:-

go build -cover

Once we have our binary file ready,this command will start the recording of API calls using ebpf:-

sudo -E keploy record -c "./test-app-product-catelog"

Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.

Generate testcases

To genereate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl

1. Generate shortned url

curl --request POST \
  --url http://localhost:8010/product \
  --header 'content-type: application/json' \
  --data '{
    "name":"Bubbles", 
    "price": 123
}'

this will return the response.

{
    "id": 1,
    "name": "Bubbles",
    "price": 123
}

2. Fetch the Products

curl --request GET \
  --url http://localhost:8010/products

we will get output:

[{"id":1,"name":"Bubbles","price":123},{"id":2,"name":"Bubbles","price":123}]

3. Fetch a single product

curl --request GET \
  --url http://localhost:8010/product/1

we will get output:-
```json
{"id":1,"name":"Bubbles","price":123}

Now, since these API calls were captured as editable testcases and written to keploy/tests folder. The keploy directory would also have mocks files that contains all the outputs of postgres operations.

Testcase

Now let's run the test mode (in the mux-sql directory, not the Keploy directory).

sudo -E keploy test -c "./test-app-product-catelog" --delay 10 --goCoverage

Once done, you can see the Test Runs on the Keploy server, like this:

Testrun

So no need to setup fake database/apis like Postgres or write mocks for them. Keploy automatically mocks them and, The application thinks it's talking to Postgres ๐Ÿ˜„

With the three API calls that we made, we got around 55.6% of coverage

test coverage

devpod-keploy's People

Contributors

sonichigo avatar

Watchers

 avatar  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.