From 8613564c1d5d4b285c50835221c6985f2422caea Mon Sep 17 00:00:00 2001 From: KirtiRamchandani Date: Mon, 25 May 2026 22:57:38 +0530 Subject: [PATCH 1/2] Add attestation marshal tests --- github/attestations_test.go | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 github/attestations_test.go diff --git a/github/attestations_test.go b/github/attestations_test.go new file mode 100644 index 00000000000..9ba48320df5 --- /dev/null +++ b/github/attestations_test.go @@ -0,0 +1,71 @@ +// Copyright 2024 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "encoding/json" + "testing" +) + +func TestAttestation_Marshal(t *testing.T) { + testJSONMarshalOnly(t, &Attestation{}, `{"bundle": null, "repository_id": 0}`) + + u := &Attestation{ + Bundle: json.RawMessage(`{"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json"}`), + RepositoryID: 1, + } + + want := `{ + "bundle": { + "mediaType": "application/vnd.dev.sigstore.bundle.v0.3+json" + }, + "repository_id": 1 + }` + + testJSONMarshal(t, u, want, cmpJSONRawMessageComparator()) +} + +func TestAttestationsResponse_Marshal(t *testing.T) { + testJSONMarshal(t, &AttestationsResponse{}, `{"attestations": null}`) + + u := &AttestationsResponse{ + Attestations: []*Attestation{ + { + Bundle: json.RawMessage(`{"verificationMaterial":{"certificate":{"rawBytes":"abc"}}}`), + RepositoryID: 1, + }, + { + Bundle: json.RawMessage(`{"dsseEnvelope":{"payload":"def"}}`), + RepositoryID: 2, + }, + }, + } + + want := `{ + "attestations": [ + { + "bundle": { + "verificationMaterial": { + "certificate": { + "rawBytes": "abc" + } + } + }, + "repository_id": 1 + }, + { + "bundle": { + "dsseEnvelope": { + "payload": "def" + } + }, + "repository_id": 2 + } + ] + }` + + testJSONMarshal(t, u, want, cmpJSONRawMessageComparator()) +} From d40cb978086391bed8115ca709affc454b9a5bee Mon Sep 17 00:00:00 2001 From: KirtiRamchandani Date: Tue, 26 May 2026 10:07:39 +0530 Subject: [PATCH 2/2] Update attestation test copyright year --- github/attestations_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/attestations_test.go b/github/attestations_test.go index 9ba48320df5..124fb640378 100644 --- a/github/attestations_test.go +++ b/github/attestations_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 The go-github AUTHORS. All rights reserved. +// Copyright 2026 The go-github AUTHORS. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.