extension

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2020 License: MIT Imports: 9 Imported by: 0

README

Godog Extensions

This library contains the following set of Godog extensions:

  • Postgres Cleanup:

    • Truncates all the tables in the public schemaname before each scenarios
    • Must have an already running postgres db
  • Gomega Fail Handler:

    • A matcher/assertion library to use with godog
  • Wiremock:

    • An extension to be able to mock requests and responses in godog tests
    • Must have an already running WireMock server

Installation

go get -v github.com/sergiughf/godog-extensions

Usage

package main

import (
    "github.com/cucumber/godog"
    "github.com/sergiughf/godog-extensions"
)

func FeatureContext(s *godog.Suite) {
	extension.NewGomegaFailHandler(s)
	extension.NewPostgresCleanup(s, postgresDSN)
	extension.NewWireMock(s, wireMockServerURL)
}

Inside the step definitions to set up a wiremock response/request:


wmClient := extension.WireMockClient()

wmClient.Request = extension.WireMockRequest{
    Method: http.MethodGet,
    URL:    "/v1/recipes?country=" + country,
}

wmClient.Response = extension.WireMockResponse{
    Status:  http.StatusOK,
    Headers: map[string]string{"Content-Type": "application/json"},
    Body:    string(body),
}

wmClient.SendMocks()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGomegaFailHandler

func NewGomegaFailHandler(ctx *godog.ScenarioContext)

NewGomegaFailHandler registers gomega fail handler

func NewPostgresCleanup

func NewPostgresCleanup(ctx *godog.ScenarioContext, postgresDSN string)

NewPostgresCleanup executes a query before each scenario in order to clean the postgres db

func NewWireMock

func NewWireMock(ctx *godog.ScenarioContext, serverURL string)

NewWireMock sets the server url on the WireMock struct and resets mocks before scenarios

Types

type WireMock

type WireMock struct {
	Request  WireMockRequest  `json:"request"`
	Response WireMockResponse `json:"response"`
	// contains filtered or unexported fields
}

WireMock holds the request and response we will store on the WireMock server

func WireMockClient

func WireMockClient() WireMock

func (*WireMock) ResetMocks

func (w *WireMock) ResetMocks() error

ResetMocks will reset all stored mocks on the WireMock server

func (*WireMock) SendMocks

func (w *WireMock) SendMocks() error

SendMocks submits the mocks to the WireMock server

type WireMockRequest

type WireMockRequest struct {
	Method string `json:"method"`
	URL    string `json:"url"`
}

WireMockRequest represents the request structure of a mock

type WireMockResponse

type WireMockResponse struct {
	Status  int               `json:"status"`
	Headers map[string]string `json:"headers"`
	Body    string            `json:"body"`
}

WireMockResponse represents the response structure of a mock

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL