jsonfieldstest

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpectCommandToSupportJSONFields

func ExpectCommandToSupportJSONFields[T any](t *testing.T, fn NewCmdFunc[T], expectedFields []string)

ExpectCommandToSupportJSONFields asserts that the provided command supports exactly the provided fields. Ordering of the expected fields is not important.

Make sure you are not pointing to the same slice of fields in the test and the implementation. It can be a little tedious to rewrite the fields inline in the test but it's significantly more useful because:

  • It forces the test author to think about and convey exactly the expected fields for a command
  • It avoids accidentally adding fields to a command, and the test passing unintentionally

Types

type NewCmdFunc

type NewCmdFunc[T any] func(f *cmdutil.Factory, runF func(*T) error) *cobra.Command

NewCmdFunc represents the typical function signature we use for creating commands e.g. `NewCmdView`.

It is generic over `T` as each command construction has their own Options type e.g. `ViewOptions`

Jump to

Keyboard shortcuts

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