@@ -92,6 +92,54 @@ func TestPublicKey_UnmarshalJSON(t *testing.T) {
9292 }
9393}
9494
95+ func TestPublicKey_MarshalJSON (t * testing.T ) {
96+ t .Parallel ()
97+ testCases := map [string ]struct {
98+ input PublicKey
99+ wantJSON string
100+ wantErr bool
101+ }{
102+ "Empty" : {
103+ input : PublicKey {},
104+ wantJSON : `{"key_id":null,"key":null}` ,
105+ wantErr : false ,
106+ },
107+ "Valid KeyID and Key" : {
108+ input : PublicKey {KeyID : Ptr ("1234" ), Key : Ptr ("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234" )},
109+ wantJSON : `{"key_id":"1234","key":"2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234"}` ,
110+ wantErr : false ,
111+ },
112+ "Nil KeyID" : {
113+ input : PublicKey {KeyID : nil , Key : Ptr ("abc" )},
114+ wantJSON : `{"key_id":null,"key":"abc"}` ,
115+ wantErr : false ,
116+ },
117+ "Nil Key" : {
118+ input : PublicKey {KeyID : Ptr ("1234" ), Key : nil },
119+ wantJSON : `{"key_id":"1234","key":null}` ,
120+ wantErr : false ,
121+ },
122+ }
123+
124+ for name , tt := range testCases {
125+ t .Run (name , func (t * testing.T ) {
126+ t .Parallel ()
127+ data , err := json .Marshal (tt .input )
128+ if err != nil && ! tt .wantErr {
129+ t .Errorf ("PublicKey.MarshalJSON returned an unexpected error: %+v" , err )
130+ }
131+ if err == nil && tt .wantErr {
132+ t .Error ("PublicKey.MarshalJSON returned nil instead of an error" )
133+ }
134+ got := string (data )
135+ if got != tt .wantJSON {
136+ t .Errorf ("PublicKey.MarshalJSON expected JSON %s, got %s" , tt .wantJSON , got )
137+ }
138+ })
139+ }
140+ }
141+
142+
95143func TestActionsService_GetRepoPublicKey (t * testing.T ) {
96144 t .Parallel ()
97145 client , mux , _ := setup (t )
0 commit comments