Skip to content

Commit a79e405

Browse files
authored
Add test case for JSON resource marshaling (#3076)
1 parent 8bb3d09 commit a79e405

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed

github/security_advisories_test.go

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,3 +1159,172 @@ func TestGetGlobalSecurityAdvisories(t *testing.T) {
11591159
return resp, err
11601160
})
11611161
}
1162+
1163+
func TestSecurityAdvisorySubmission_Marshal(t *testing.T) {
1164+
testJSONMarshal(t, &SecurityAdvisorySubmission{}, `{}`)
1165+
1166+
u := &SecurityAdvisorySubmission{
1167+
Accepted: Bool(true),
1168+
}
1169+
1170+
w := `{
1171+
"accepted": true
1172+
}`
1173+
1174+
testJSONMarshal(t, u, w)
1175+
}
1176+
1177+
func TestRepoAdvisoryCredit_Marshal(t *testing.T) {
1178+
testJSONMarshal(t, &RepoAdvisoryCredit{}, `{}`)
1179+
1180+
u := &RepoAdvisoryCredit{
1181+
Login: String("l"),
1182+
Type: String("t"),
1183+
}
1184+
1185+
w := `{
1186+
"login": "l",
1187+
"type": "t"
1188+
}`
1189+
1190+
testJSONMarshal(t, u, w)
1191+
}
1192+
1193+
func TestRepoAdvisoryCreditDetailed_Marshal(t *testing.T) {
1194+
testJSONMarshal(t, &RepoAdvisoryCreditDetailed{}, `{}`)
1195+
1196+
testDate := &Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}
1197+
u := &RepoAdvisoryCreditDetailed{
1198+
Type: String("t"),
1199+
State: String("s"),
1200+
User: &User{
1201+
Name: String("u"),
1202+
Company: String("c"),
1203+
Blog: String("b"),
1204+
Location: String("l"),
1205+
Email: String("e"),
1206+
Hireable: Bool(false),
1207+
Bio: String("bio"),
1208+
TwitterUsername: String("tu"),
1209+
PublicRepos: Int(1),
1210+
PublicGists: Int(1),
1211+
Followers: Int(2),
1212+
Following: Int(2),
1213+
CreatedAt: testDate,
1214+
UpdatedAt: testDate,
1215+
SuspendedAt: testDate,
1216+
Type: String("type"),
1217+
SiteAdmin: Bool(false),
1218+
TotalPrivateRepos: Int64(10),
1219+
OwnedPrivateRepos: Int64(10),
1220+
PrivateGists: Int(10),
1221+
DiskUsage: Int(10),
1222+
Collaborators: Int(10),
1223+
TwoFactorAuthentication: Bool(true),
1224+
Plan: &Plan{
1225+
Name: String("p"),
1226+
Space: Int(2),
1227+
Collaborators: Int(2),
1228+
PrivateRepos: Int64(2),
1229+
Seats: Int(2),
1230+
FilledSeats: Int(1),
1231+
},
1232+
LdapDn: String("l"),
1233+
URL: String("url"),
1234+
EventsURL: String("e"),
1235+
FollowingURL: String("f"),
1236+
FollowersURL: String("f"),
1237+
GistsURL: String("g"),
1238+
OrganizationsURL: String("o"),
1239+
ReceivedEventsURL: String("r"),
1240+
ReposURL: String("rep"),
1241+
StarredURL: String("star"),
1242+
SubscriptionsURL: String("sub"),
1243+
TextMatches: []*TextMatch{
1244+
{
1245+
ObjectURL: String("u"),
1246+
ObjectType: String("t"),
1247+
Property: String("p"),
1248+
Fragment: String("f"),
1249+
Matches: []*Match{
1250+
{
1251+
Text: String("t"),
1252+
Indices: []int{1, 2},
1253+
},
1254+
},
1255+
},
1256+
},
1257+
Permissions: map[string]bool{"p1": true},
1258+
RoleName: String("r"),
1259+
},
1260+
}
1261+
1262+
w := `{
1263+
"type": "t",
1264+
"state": "s",
1265+
"user": {
1266+
"name": "u",
1267+
"company": "c",
1268+
"blog": "b",
1269+
"location": "l",
1270+
"email": "e",
1271+
"hireable": false,
1272+
"bio": "bio",
1273+
"twitter_username": "tu",
1274+
"public_repos": 1,
1275+
"public_gists": 1,
1276+
"followers": 2,
1277+
"following": 2,
1278+
"created_at": "2019-08-10T14:59:22Z",
1279+
"updated_at": "2019-08-10T14:59:22Z",
1280+
"suspended_at": "2019-08-10T14:59:22Z",
1281+
"type": "type",
1282+
"site_admin": false,
1283+
"total_private_repos": 10,
1284+
"owned_private_repos": 10,
1285+
"private_gists": 10,
1286+
"disk_usage": 10,
1287+
"collaborators": 10,
1288+
"two_factor_authentication": true,
1289+
"plan": {
1290+
"name": "p",
1291+
"space": 2,
1292+
"collaborators": 2,
1293+
"private_repos": 2,
1294+
"seats": 2,
1295+
"filled_seats": 1
1296+
},
1297+
"ldap_dn": "l",
1298+
"url": "url",
1299+
"events_url": "e",
1300+
"following_url": "f",
1301+
"followers_url": "f",
1302+
"gists_url": "g",
1303+
"organizations_url": "o",
1304+
"received_events_url": "r",
1305+
"repos_url": "rep",
1306+
"starred_url": "star",
1307+
"subscriptions_url": "sub",
1308+
"text_matches": [
1309+
{
1310+
"object_url": "u",
1311+
"object_type": "t",
1312+
"property": "p",
1313+
"fragment": "f",
1314+
"matches": [
1315+
{
1316+
"text": "t",
1317+
"indices": [1, 2]
1318+
}
1319+
]
1320+
}
1321+
],
1322+
"permissions": {
1323+
"p1": true
1324+
},
1325+
"role_name": "r"
1326+
}
1327+
}`
1328+
1329+
testJSONMarshal(t, u, w)
1330+
}

0 commit comments

Comments
 (0)