Skip to content

Commit c86868e

Browse files
Add test cases for JSON resource marshaling (#2531)
1 parent f9d2c6b commit c86868e

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

github/secret_scanning_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,113 @@ func TestSecretScanningService_ListLocationsForAlert(t *testing.T) {
475475
return resp, err
476476
})
477477
}
478+
479+
func TestSecretScanningAlert_Marshal(t *testing.T) {
480+
testJSONMarshal(t, &SecretScanningAlert{}, `{}`)
481+
482+
u := &SecretScanningAlert{
483+
Number: Int(1),
484+
CreatedAt: &Timestamp{referenceTime},
485+
URL: String("https://api.github.com/teams/2/discussions/3/comments"),
486+
HTMLURL: String("https://api.github.com/teams/2/discussions/3/comments"),
487+
LocationsURL: String("https://api.github.com/teams/2/discussions/3/comments"),
488+
State: String("test_state"),
489+
Resolution: String("test_resolution"),
490+
ResolvedAt: &Timestamp{referenceTime},
491+
ResolvedBy: &User{
492+
Login: String("test"),
493+
ID: Int64(10),
494+
NodeID: String("A123"),
495+
AvatarURL: String("https://api.github.com/teams/2/discussions/3/comments"),
496+
},
497+
SecretType: String("test"),
498+
Secret: String("test"),
499+
}
500+
501+
want := `{
502+
"number": 1,
503+
"created_at": ` + referenceTimeStr + `,
504+
"url": "https://api.github.com/teams/2/discussions/3/comments",
505+
"html_url": "https://api.github.com/teams/2/discussions/3/comments",
506+
"locations_url": "https://api.github.com/teams/2/discussions/3/comments",
507+
"state": "test_state",
508+
"resolution": "test_resolution",
509+
"resolved_at": ` + referenceTimeStr + `,
510+
"resolved_by": {
511+
"login": "test",
512+
"id": 10,
513+
"node_id": "A123",
514+
"avatar_url": "https://api.github.com/teams/2/discussions/3/comments"
515+
},
516+
"secret_type": "test",
517+
"secret": "test"
518+
}`
519+
520+
testJSONMarshal(t, u, want)
521+
}
522+
523+
func TestSecretScanningAlertLocation_Marshal(t *testing.T) {
524+
testJSONMarshal(t, &SecretScanningAlertLocation{}, `{}`)
525+
526+
u := &SecretScanningAlertLocation{
527+
Type: String("test"),
528+
Details: &SecretScanningAlertLocationDetails{
529+
Path: String("test_path"),
530+
Startline: Int(10),
531+
EndLine: Int(20),
532+
StartColumn: Int(30),
533+
EndColumn: Int(40),
534+
BlobSHA: String("test_sha"),
535+
BlobURL: String("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"),
536+
CommitSHA: String("test_sha"),
537+
CommitURL: String("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"),
538+
},
539+
}
540+
541+
want := `{
542+
"type": "test",
543+
"details": {
544+
"path": "test_path",
545+
"start_line": 10,
546+
"end_line": 20,
547+
"start_column": 30,
548+
"end_column": 40,
549+
"blob_sha": "test_sha",
550+
"blob_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b",
551+
"commit_sha": "test_sha",
552+
"commit_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"
553+
}
554+
}`
555+
556+
testJSONMarshal(t, u, want)
557+
}
558+
559+
func TestSecretScanningAlertLocationDetails_Marshal(t *testing.T) {
560+
testJSONMarshal(t, &SecretScanningAlertLocationDetails{}, `{}`)
561+
562+
u := &SecretScanningAlertLocationDetails{
563+
Path: String("test_path"),
564+
Startline: Int(10),
565+
EndLine: Int(20),
566+
StartColumn: Int(30),
567+
EndColumn: Int(40),
568+
BlobSHA: String("test_sha"),
569+
BlobURL: String("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"),
570+
CommitSHA: String("test_sha"),
571+
CommitURL: String("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"),
572+
}
573+
574+
want := `{
575+
"path": "test_path",
576+
"start_line": 10,
577+
"end_line": 20,
578+
"start_column": 30,
579+
"end_column": 40,
580+
"blob_sha": "test_sha",
581+
"blob_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b",
582+
"commit_sha": "test_sha",
583+
"commit_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"
584+
}`
585+
586+
testJSONMarshal(t, u, want)
587+
}

0 commit comments

Comments
 (0)