Skip to content

tests/fields: False positive for fields with null values, reported as "missing" incorrectly. #576

Open
@dmitshur

Description

@dmitshur

There appears to be a bug in the ./tests/fields test/utility, causing some fields to be falsely reported as "missing".

For example, in the following test case:

{"repos/google/go-github/issues/1", &github.Issue{}},

The real GitHub API response from https://api.github.com/repos/google/go-github/issues/1 includes:

...
    "site_admin": false
    }
  ],
  "milestone": null,
  "comments": 2,
  "created_at": "2013-05-30T18:35:59Z",
  "updated_at": "2013-08-20T22:47:14Z",
...

Note that the value of milestone is null.

The corresponding struct field Issue.Milestone exists:

Milestone *Milestone `json:"milestone,omitempty"`

But the output from the fields test incorrectly reports:

...
*github.Issue missing field for key: milestone (example value: <nil>)
...

I think it's because the null value gets dropped when JSON marshalling the Issue struct, because of ,omitempty option.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions