Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions github/attestations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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.

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())
}