Skip to content
Merged
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
Add test cases for JSON resource marshaling
  • Loading branch information
sayalideshmukh10 committed Oct 26, 2022
commit 485b68b3e25a3561f8f39b6264d650b96e65fdd3
110 changes: 110 additions & 0 deletions github/secret_scanning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,113 @@ func TestSecretScanningService_ListLocationsForAlert(t *testing.T) {
return resp, err
})
}

func TestSecretScanningAlert_Marshal(t *testing.T) {
testJSONMarshal(t, &SecretScanningAlert{}, `{}`)

u := &SecretScanningAlert{
Number: Int(1),
CreatedAt: &Timestamp{referenceTime},
URL: String("https://api.github.com/teams/2/discussions/3/comments"),
HTMLURL: String("https://api.github.com/teams/2/discussions/3/comments"),
LocationsURL: String("https://api.github.com/teams/2/discussions/3/comments"),
State: String("test_state"),
Resolution: String("test_resolution"),
ResolvedAt: &Timestamp{referenceTime},
ResolvedBy: &User{
Login: String("test"),
ID: Int64(10),
NodeID: String("A123"),
AvatarURL: String("https://api.github.com/teams/2/discussions/3/comments"),
},
SecretType: String("test"),
Secret: String("test"),
}

want := `{
"number": 1,
"created_at": ` + referenceTimeStr + `,
"url": "https://api.github.com/teams/2/discussions/3/comments",
"html_url": "https://api.github.com/teams/2/discussions/3/comments",
"locations_url": "https://api.github.com/teams/2/discussions/3/comments",
"state": "test_state",
"resolution": "test_resolution",
"resolved_at": ` + referenceTimeStr + `,
"resolved_by": {
"login": "test",
"id": 10,
"node_id": "A123",
"avatar_url": "https://api.github.com/teams/2/discussions/3/comments"
},
"secret_type": "test",
"secret": "test"
}`

testJSONMarshal(t, u, want)
}

func TestSecretScanningAlertLocation_Marshal(t *testing.T) {
testJSONMarshal(t, &SecretScanningAlertLocation{}, `{}`)

u := &SecretScanningAlertLocation{
Type: String("test"),
Details: &SecretScanningAlertLocationDetails{
Path: String("test_path"),
Startline: Int(10),
EndLine: Int(20),
StartColumn: Int(30),
EndColumn: Int(40),
BlobSHA: String("test_sha"),
BlobURL: String("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"),
CommitSHA: String("test_sha"),
CommitURL: String("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"),
},
}

want := `{
"type": "test",
"details": {
"path": "test_path",
"start_line": 10,
"end_line": 20,
"start_column": 30,
"end_column": 40,
"blob_sha": "test_sha",
"blob_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b",
"commit_sha": "test_sha",
"commit_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"
}
}`

testJSONMarshal(t, u, want)
}

func TestSecretScanningAlertLocationDetails_Marshal(t *testing.T) {
testJSONMarshal(t, &SecretScanningAlertLocationDetails{}, `{}`)

u := &SecretScanningAlertLocationDetails{
Path: String("test_path"),
Startline: Int(10),
EndLine: Int(20),
StartColumn: Int(30),
EndColumn: Int(40),
BlobSHA: String("test_sha"),
BlobURL: String("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"),
CommitSHA: String("test_sha"),
CommitURL: String("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"),
}

want := `{
"path": "test_path",
"start_line": 10,
"end_line": 20,
"start_column": 30,
"end_column": 40,
"blob_sha": "test_sha",
"blob_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b",
"commit_sha": "test_sha",
"commit_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"
}`

testJSONMarshal(t, u, want)
}