Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertJSON ¶ added in v0.2.0
AssertJSON compares the expected JSON (want) with the actual value (got), and if they are different it marks the test as failed, but continues execution. The expected JSON is read from a golden file.
To update the golden file with the actual value instead of comparing with it, set the update flag to true.
Types ¶
type FieldComment ¶ added in v0.2.0
type FieldComment struct { // Path is the GJSON path to the field. // See https://github.com/tidwall/gjson/blob/master/SYNTAX.md // // Example: "data.user.name" for the following JSON: // // { // "data": { // "user": { // "name": "John", // } // } // } Path string // Comment is the comment that describes what to look for when inspecting the JSON field. Comment string }
FieldComment is a comment that describes what to look for when inspecting the JSON field. The comment is added to the field specified by its Path.
type Option ¶ added in v0.2.0
Option is a function that modifies the golden file. It is used to apply modifications to the golden file before comparing it with the actual result.
func FieldComments ¶ added in v0.2.0
func FieldComments(fieldComments ...FieldComment) Option
FieldComments adds comments to fields in the golden file. This is useful for making it easier for the reader to understand what to look for when inspecting the JSON field.
Example: { "age": 30, // This my field comment }
NOTE! Adding comments to JSON makes it invalid, since JSON does not support comments. To keep you IDE happy, i.e., for it not to show errors, make the file extension .jsonc. To do that, make sure the "want" file argument in the JSON() function call has the .jsonc extension.
func FileComment ¶ added in v0.2.0
FileComment adds a comment to the top of the golden file. This is useful for providing context to the reader.
NOTE! Adding comments to JSON makes it invalid, since JSON does not support comments. To keep you IDE happy, i.e., for it not to show errors, make the file extension .jsonc. To do that, make sure the "want" file argument in the JSON() function call has the .jsonc extension.
func SkipFields ¶ added in v0.2.1
SkipFields replaces the value of the fields with "--* SKIPPED *--". The fields are specified by their GJSON path. See https://github.com/tidwall/gjson/blob/master/SYNTAX.md
The rules are as follows:
- If the field is a nilable type and is nil, then it is not marked as skipped, since its "null" value is already deterministic.
- If the field is a nilable type and has a non-nil value, then it is marked as skipped.
- If the field is a non-nilable type, then it is marked as skipped.
Example: "data.user.Name" for the following JSON:
{ "data": { "user": { "Name": "--* SKIPPED *--", } } }