Skip to content

test: Add attestation marshal tests - #4253

Closed
KirtiRamchandani wants to merge 2 commits into
google:masterfrom
KirtiRamchandani:test/attestations-marshal
Closed

test: Add attestation marshal tests#4253
KirtiRamchandani wants to merge 2 commits into
google:masterfrom
KirtiRamchandani:test/attestations-marshal

Conversation

@KirtiRamchandani

Copy link
Copy Markdown
Contributor

Problem
Artifact attestation payload types are shared by organization, repository, and user attestation APIs, but the shared resource structs did not have dedicated JSON marshal coverage tracked by #55.

Root cause
Existing service tests exercise API decoding paths, while the resource-level marshal round-trip tests skipped Attestation and AttestationsResponse.

Solution
Add marshal tests for empty and populated Attestation and AttestationsResponse values. The populated cases use the existing json.RawMessage comparator so Sigstore bundle JSON is compared semantically.

Tests run

  • gofmt -w github/attestations_test.go
  • go test ./github -run 'TestAttestation(sResponse)?_Marshal'
  • go test ./github
  • go test ./...
  • git diff --cached --check

Linked issue
Part of #55

@gmlewisgmlewis added the NeedsReview PR is awaiting a review before merging. label May 26, 2026
@gmlewisgmlewis changed the title Add attestation marshal testschore: Add attestation marshal testsMay 26, 2026
Comment threadgithub/attestations_test.go Outdated
@@ -0,0 +1,71 @@
// Copyright 2024 The go-github AUTHORS. All rights reserved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright 2024 The go-github AUTHORS. All rights reserved.
// Copyright 2026 The go-github AUTHORS. All rights reserved.

@codecov

codecovBot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.48%. Comparing base (c207b27) to head (8613564).

Additional details and impacted files
@@ Coverage Diff @@## master #4253 +/- ##
=======================================
Coverage 97.48% 97.48% =======================================
Files 190 190 Lines 19178 19178 =======================================
Hits 18695 18695 Misses 268 268 Partials 215 215 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KirtiRamchandani

Copy link
Copy Markdown
ContributorAuthor

Thanks, updated the new test file copyright year to 2026 and reran the focused marshal test plus diff check.

Comment on lines +13 to +14
func TestAttestation_Marshal(t *testing.T) {
testJSONMarshalOnly(t, &Attestation{}, `{"bundle": null, "repository_id": 0}`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
funcTestAttestation_Marshal(t*testing.T) {
testJSONMarshalOnly(t, &Attestation{}, `{"bundle": null, "repository_id": 0}`)
funcTestAttestation_Marshal(t*testing.T) {
t.Parallel()
testJSONMarshalOnly(t, &Attestation{}, `{"bundle": null, "repository_id": 0}`)

Comment on lines +31 to +32
func TestAttestationsResponse_Marshal(t *testing.T) {
testJSONMarshal(t, &AttestationsResponse{}, `{"attestations": null}`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
funcTestAttestationsResponse_Marshal(t*testing.T) {
testJSONMarshal(t, &AttestationsResponse{}, `{"attestations": null}`)
funcTestAttestationsResponse_Marshal(t*testing.T) {
t.Parallel()
testJSONMarshal(t, &AttestationsResponse{}, `{"attestations": null}`)

@gmlewisgmlewis changed the title chore: Add attestation marshal teststest: Add attestation marshal testsMay 26, 2026

@alexandearalexandear left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for Attestation and AttestationsResponse JSON marshal tests. We should only add tests for types with custom MarshalJSON or UnmarshalJSON implementations. For example:

@gmlewis what do you think? These tests, generated by an LLM, don't actually validate anything meaningful and only add maintenance overhead.

@gmlewis

Copy link
Copy Markdown
Collaborator

No need for Attestation and AttestationsResponse JSON marshal tests. We should only add tests for types with custom MarshalJSON or UnmarshalJSON implementations. For example:

@gmlewis what do you think? These tests, generated by an LLM, don't actually validate anything meaningful and only add maintenance overhead.

@alexandear - that's a good point. I'm wondering if #55 should simply be closed now and we should stop "advertising" this open-ended invitation for PRs. This one issue was the sole target for previous Hacktoberfest contributions, and maybe it is no longer really needed. Thoughts?

@alexandear

Copy link
Copy Markdown
Contributor

This one issue was the sole target for previous Hacktoberfest contributions, and maybe it is no longer really needed. Thoughts?

I vote for closing the issue.

Also, we can simply write a tool to generate marshal/unmarshal tests. But I'm not sure if we need.

@gmlewis

Copy link
Copy Markdown
Collaborator

This one issue was the sole target for previous Hacktoberfest contributions, and maybe it is no longer really needed. Thoughts?

I vote for closing the issue.

Also, we can simply write a tool to generate marshal/unmarshal tests. But I'm not sure if we need.

Agreed. Thank you, @alexandear, and thank you, @KirtiRamchandani for your understanding. Closing.

@gmlewisgmlewis closed this May 27, 2026
tommaso-moro added a commit to tommaso-moro/go-github that referenced this pull request Jun 22, 2026
IssueDependencyRequest has no custom MarshalJSON, so the test only
exercises the standard library's encoding/json. Per the project
convention (google#4253), marshal tests are reserved for
types with custom (Un)MarshalJSON implementations.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NeedsReviewPR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@KirtiRamchandani@gmlewis@alexandear@Not-Dhananjay-Mishra