MCPcopy Create free account
hub / github.com/cli/cli / ExpectCommandToSupportJSONFields

Function ExpectCommandToSupportJSONFields

pkg/jsonfieldstest/jsonfieldstest.go:41–47  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

39// - It forces the test author to think about and convey exactly the expected fields for a command
40// - It avoids accidentally adding fields to a command, and the test passing unintentionally
41func ExpectCommandToSupportJSONFields[T any](t *testing.T, fn NewCmdFunc[T], expectedFields []string) {
42 t.Helper()
43
44 actualFields := jsonFieldsFor(fn(&cmdutil.Factory{}, nil))
45 assert.Equal(t, len(actualFields), len(expectedFields), "expected number of fields to match")
46 require.ElementsMatch(t, expectedFields, actualFields)
47}

Callers 12

TestJSONFieldsFunction · 0.92
TestListJSONFieldsFunction · 0.92
TestJSONFieldsFunction · 0.92
TestJSONFieldsFunction · 0.92
TestJSONFieldsFunction · 0.92
TestJSONFieldsFunction · 0.92
TestJSONFieldsFunction · 0.92
TestJSONFieldsFunction · 0.92
TestJSONFieldsFunction · 0.92
TestJSONFieldsFunction · 0.92
TestJSONFieldsFunction · 0.92
TestJSONFieldsFunction · 0.92

Calls 3

jsonFieldsForFunction · 0.85
EqualMethod · 0.80
HelperMethod · 0.65

Tested by 12

TestJSONFieldsFunction · 0.74
TestListJSONFieldsFunction · 0.74
TestJSONFieldsFunction · 0.74
TestJSONFieldsFunction · 0.74
TestJSONFieldsFunction · 0.74
TestJSONFieldsFunction · 0.74
TestJSONFieldsFunction · 0.74
TestJSONFieldsFunction · 0.74
TestJSONFieldsFunction · 0.74
TestJSONFieldsFunction · 0.74
TestJSONFieldsFunction · 0.74
TestJSONFieldsFunction · 0.74