Documentation ¶
Overview ¶
Package diff provides some convenience functions for comparing text in various forms. It's primary use case is in automated testing.
Deprecated: This package is no longer maintained. Please use gitlab.com/flimzy/testy instead.
Index ¶
- Constants
- type File
- type Result
- func AsJSON(expected, actual interface{}) *Result
- func DirChecksum(expected map[string]string, dir string) *Result
- func DirFullCheck(expected map[string]string, dir string) *Result
- func HTTPRequest(expected, actual interface{}) *Result
- func HTTPResponse(expected, actual interface{}) *Result
- func Interface(expected, actual interface{}) *Result
- func JSON(expected, actual []byte) *Result
- func Text(expected, actual interface{}) *Result
- func TextSlices(expected, actual []string) *Result
Constants ¶
const UpdateMode = false
UpdateMode indicates whether a detected diff should cause a File to be overwritten. To enable UpdateMode, run `go test -tag=update`.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶ added in v0.1.6
type File struct { Path string // contains filtered or unexported fields }
File converts a file into an io.Reader. When UpdateMode is true, a dected difference will cause File to be overwritten with the actual value, when File is the expected value.
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 DirChecksum ¶ added in v0.1.4
DirChecksum compares the checksum of the contents of dir against the checksums in expected. Expected should be a map of all files expected in the directory, with the full path and filename as key, and the md5 sum as the value.
func DirFullCheck ¶ added in v0.1.5
DirFullCheck compares the checksum of the contents of dir against the checksums in expected. Expected should be a map of all files expected in the directory, with the full path and filename as key, and the md5 sum, mode, and ownership as the value.
func HTTPRequest ¶ added in v0.1.3
func HTTPRequest(expected, actual interface{}) *Result
HTTPRequest compares the metadata and bodies of the two HTTP requests, and returns the difference. Inputs must be of the type *http.Request, or of one of the following types, in which case the input is interpreted as a raw HTTP request. - io.Reader - string - []byte
func HTTPResponse ¶ added in v0.1.3
func HTTPResponse(expected, actual interface{}) *Result
HTTPResponse compares the metadata and bodies of the two HTTP responses, and returns the difference. Inputs must be of the type *http.Response, or of one of the following types, in which case the input is interpreted as a raw HTTP response. - io.Reader - string - []byte
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 ¶
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 ¶
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.