diff

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2018 License: MIT Imports: 12 Imported by: 2

README

Build Status Codecov GoDoc

diff

This is a simple package to facilitate Go testing of various deeply nested data types.

License

This package is released under the terms of the MIT license. See the included LICENSE.txt for details.

Documentation

Overview

Package diff provides some convenience functions for comparing text in various forms. It's primary use case is in automated testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result is the result of a diff function. It may be nil, if the inputs were considered identical, or accessed via the String() method to return the diff. Any errors are returned as their textual representation via String() as well.

func AsJSON

func AsJSON(expected, actual interface{}) *Result

AsJSON marshals two objects as JSON, then compares the output. If an input object is an io.Reader, it is treated as a JSON stream. If it is a []byte or json.RawMessage, it is treated as raw JSON. Any raw JSON source is unmarshaled then remarshaled with indentation for normalization and comparison.

func HTTPRequest added in v0.1.3

func HTTPRequest(expected, actual *http.Request) *Result

HTTPRequest compares the metadata and bodies of the two HTTP requests, and returns the difference.

func HTTPResponse added in v0.1.3

func HTTPResponse(expected, actual *http.Response) *Result

HTTPResponse compares the metadata and bodies of the two HTTP responses, and returns the difference.

func Interface

func Interface(expected, actual interface{}) *Result

Interface compares two objects with reflect.DeepEqual, and if they differ, it returns a diff of the spew.Dump() outputs

func JSON

func JSON(expected, actual []byte) *Result

JSON unmarshals two JSON strings, then calls AsJSON on them. As a special case, empty byte arrays are unmarshaled to nil.

func Text

func Text(expected, actual interface{}) *Result

Text compares two strings, line-by-line, for differences. expected and actual must be of one of the following types: - string - []byte - io.Reader

func TextSlices

func TextSlices(expected, actual []string) *Result

TextSlices compares two slices of text, treating each element as a line of text. Newlines are added to each element, if they are found to be missing.

func (*Result) String

func (r *Result) String() string

Jump to

Keyboard shortcuts

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