Testing only the JSON fields a CLI consumer needs, not the whole output
A GitLab CLI test for the glab securefile get command failed after the Go SDK added a field, even though consuming scripts still worked. The test had compared the entire serialized object, so one extra field broke the assertion. The article recommends decoding the output into a small test-owned struct and checking only the required fields, such as ID and checksum, since Go's JSON decoder ignores unknown fields by default. It also notes that pointer fields help distinguish missing or null values from valid zero values. The author reports that an added field passed the new assertion while removing a required field still failed it. A full-output fixture remains appropriate when the exact schema is part of the contract.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in