aduket

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

README

Aduket

Straight-forward HTTP client testing, assertions included!

Simple httptest.Server wrapper with a little request recorder spice on it. No special DSL, no complex API to learn. Just create a server and fire your request like an Hadouken then assert it.

Why?

Aduket's raison d'etre is to make you able to test your HTTP client related logic in ease or for some reason you just need a mock server to make it respond in a way you need.

What?

Aduket currently provides following utilities to make your testing process easier and faster:

  • Lean way to spin up a mock HTTP server to imitate different responses (even timeouts!).
  • Assertion helpers to validate if you're sending the correct request.

LICENSE

Copyright 2020 StreetByters Community

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMultiRouteServer

func NewMultiRouteServer(routeResponseOptions map[Route][]ResponseRuleOption) (*httptest.Server, map[Route]*RequestRecorder)

Types

type Body

type Body []byte

type RequestRecorder

type RequestRecorder struct {
	Body        Body
	Header      http.Header
	Data        []byte
	Params      map[string]string
	QueryParams url.Values
	FormParams  url.Values
	// contains filtered or unexported fields
}

func NewRequestRecorder

func NewRequestRecorder() *RequestRecorder

func NewServer

func NewServer(httpMethod, path string, responseRuleOptions ...ResponseRuleOption) (*httptest.Server, *RequestRecorder)

func (RequestRecorder) AssertFormParamEqual

func (r RequestRecorder) AssertFormParamEqual(t *testing.T, formParamName string, formValues []string) bool

func (RequestRecorder) AssertHeaderContains

func (r RequestRecorder) AssertHeaderContains(t *testing.T, expectedHeader http.Header) bool

func (RequestRecorder) AssertJSONBodyEqual

func (r RequestRecorder) AssertJSONBodyEqual(t *testing.T, expectedBody interface{}) bool

func (RequestRecorder) AssertNoRequest

func (r RequestRecorder) AssertNoRequest(t *testing.T) bool

func (RequestRecorder) AssertParamEqual

func (r RequestRecorder) AssertParamEqual(t *testing.T, paramName, paramValue string) bool

func (RequestRecorder) AssertQueryParamEqual

func (r RequestRecorder) AssertQueryParamEqual(t *testing.T, queryParamName string, queryParamValues []string) bool

func (RequestRecorder) AssertStringBodyEqual

func (r RequestRecorder) AssertStringBodyEqual(t *testing.T, expectedBody string) bool

func (RequestRecorder) AssertXMLBodyEqual

func (r RequestRecorder) AssertXMLBodyEqual(t *testing.T, expectedXMLBody interface{}) bool

type RequestRecorderBinder

type RequestRecorderBinder struct{}

func (*RequestRecorderBinder) Bind

func (r *RequestRecorderBinder) Bind(requestRecorder interface{}, ctx echo.Context) error

type ResponseRuleOption

type ResponseRuleOption func(*responseRule)

func ByteBody

func ByteBody(b []byte) ResponseRuleOption

func CorruptedBody

func CorruptedBody() ResponseRuleOption
func Header(header http.Header) ResponseRuleOption

func JSONBody

func JSONBody(body interface{}) ResponseRuleOption

func StatusCode

func StatusCode(statusCode int) ResponseRuleOption

func StringBody

func StringBody(str string) ResponseRuleOption

func Timeout

func Timeout(duration time.Duration) ResponseRuleOption

func XMLBody

func XMLBody(body interface{}) ResponseRuleOption

type Route

type Route struct {
	HttpMethod string
	Path       string
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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