Documentation
¶
Overview ¶
Package assertjson implements JSON equality assertion for tests.
Example ¶
package main
import (
"fmt"
"github.com/swaggest/assertjson"
)
var t = testingT(func(format string, args ...interface{}) {
fmt.Printf(format, args...)
})
func main() {
assertjson.Equal(t,
[]byte(`{"a": [1, {"val": "<ignore-diff>"}, 3], "b": 2, "c": 3}`),
[]byte(`{"a": [1, {"val": 123}, 3], "c": 2, "b": 3}`),
)
}
Output: Error Trace: equal.go:48 equal.go:36 example_test.go:14 Error: Not equal: { "a": [ 1, { "val": "<ignore-diff>" }, 3 ], - "b": 2, + "b": 3, - "c": 3 + "c": 2 }
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FailNotEqual ¶ added in v1.1.0
FailNotEqual returns error if JSON payloads are different, nil otherwise.
func MarshalIndentCompact ¶ added in v1.2.0
MarshalIndentCompact applies indentation for large chunks of JSON and uses compact format for smaller ones.
Line length limits indented width of JSON structure, does not apply to long distinct scalars. This function is not optimized for performance, so it might be not a good fit for high load scenarios.
Types ¶
type Comparer ¶
type Comparer struct {
// IgnoreDiff is a value in expected document to ignore difference with actual document.
IgnoreDiff string
// FormatterConfig controls diff formatter configuration.
FormatterConfig formatter.AsciiFormatterConfig
}
Comparer compares JSON documents.
func (Comparer) FailNotEqual ¶ added in v1.1.0
FailNotEqual returns error if JSON payloads are different, nil otherwise.
Click to show internal directories.
Click to hide internal directories.