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)
| 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 |
| 41 | func 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 | } |