Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/braspagdevelopers/mock-server-client

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/braspagdevelopers/mock-server-client

  • v0.2.2
  • Source
  • Go
  • Socket score

Version published
Created
Source

Mock Server Client - a Go package

Client for the mock-server.com product.

The focus of this library is to use within integration tests in order to verify if a specific request was made in a mocked dependency (the mock-server).

It is still work in progress.

Installation

Using go get

go get -u github.com/BraspagDevelopers/mock-server-client

Using go.mod file

require github.com/BraspagDevelopers/mock-server-client

Usage

Import the package

import (
    "github.com/BraspagDevelopers/mock-server-client"
)

Verifying a request

The folowing verifies if the mock-server received requests matching the following filters:

  • The method was POST
  • The endpoint was /api/categories
  • Having a header Environment: Development
  • The body was a JSON and the body field name had the value "Tools"
  • The request was made once and only once
ms := mockserver.NewClient("localhost", 8080)
err := ms.Verify(
    mockserver.RequestMatcher{
        Method: http.MethodPost,
        Path:   "/api/categories"}.
        WithHeader("Environment", "Development").
        WithJsonFields(map[string]interface{}{
            "name": "Tools",
        }),
    mockserver.Once())

Clearing requests

You can clear the mock-server requests in the log that matches an specific RequestMatcher using the method MockClient.Verify.

err := ms.Verify(mockserver.RequestMatcher{
    Method: http.MethodPost,
    Path:   "/api/categories"}.
    WithHeader("Environment", "Development").
    WithJsonFields(map[string]interface{}{
        "name": "Tools",
    }))

Notice that the cardinality is not specified in this request for this method. All matching requests will be erased from the log.

Verify and clear at the same time

You can also verify and clear matching requests at once by using the method MockClient.VerifyAndClear().

FAQs

Package last updated on 05 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc