Skip to content

Commit 3e83711

Browse files
committed
Added JSON marshalling test for actions_secrets_test.go
1 parent e5f03fc commit 3e83711

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

github/actions_secrets_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
95143
func TestActionsService_GetRepoPublicKey(t *testing.T) {
96144
t.Parallel()
97145
client, mux, _ := setup(t)

0 commit comments

Comments
 (0)