Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test cases for JSON marshalling #1144

Merged
merged 10 commits into from
Apr 5, 2019
56 changes: 56 additions & 0 deletions github/gists_comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,64 @@ import (
"net/http"
"reflect"
"testing"
"time"
)

func TestGistComments_marshall(t *testing.T) {
testJSONMarshal(t, &GistComment{}, "{}")

createdAt := time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)

u := &GistComment{
ID: Int64(1),
URL: String("u"),
Body: String("test gist comment"),
User: &User{
Login: String("ll"),
ID: Int64(123),
AvatarURL: String("a"),
GravatarID: String("g"),
Name: String("n"),
Company: String("c"),
Blog: String("b"),
Location: String("l"),
Email: String("e"),
Hireable: Bool(true),
PublicRepos: Int(1),
Followers: Int(1),
Following: Int(1),
CreatedAt: &Timestamp{referenceTime},
URL: String("u"),
},
CreatedAt: &createdAt,
}

want := `{
"id": 1,
"url": "u",
"body": "test gist comment",
"user": {
"login": "ll",
"id": 123,
"avatar_url": "a",
"gravatar_id": "g",
"name": "n",
"company": "c",
"blog": "b",
"location": "l",
"email": "e",
"hireable": true,
"public_repos": 1,
"followers": 1,
"following": 1,
"created_at": ` + referenceTimeStr + `,
"url": "u"
},
"created_at": "2002-02-10T15:30:00Z"
}`

testJSONMarshal(t, u, want)
}
func TestGistsService_ListComments(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down
209 changes: 209 additions & 0 deletions github/gists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,215 @@ import (
"time"
)

func TestGist_marshall(t *testing.T) {
testJSONMarshal(t, &Gist{}, "{}")

createdAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC)
updatedAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC)

u := &Gist{
ID: String("i"),
Description: String("description"),
Public: Bool(true),
Owner: &User{
Login: String("ll"),
ID: Int64(123),
AvatarURL: String("a"),
GravatarID: String("g"),
Name: String("n"),
Company: String("c"),
Blog: String("b"),
Location: String("l"),
Email: String("e"),
Hireable: Bool(true),
PublicRepos: Int(1),
Followers: Int(1),
Following: Int(1),
CreatedAt: &Timestamp{referenceTime},
URL: String("u"),
},
Files: map[GistFilename]GistFile{
"gistfile.py": {
Size: Int(167),
Filename: String("gistfile.py"),
Language: String("Python"),
Type: String("application/x-python"),
RawURL: String("raw-url"),
Content: String("c"),
},
},
Comments: Int(1),
HTMLURL: String("html-url"),
GitPullURL: String("gitpull-url"),
GitPushURL: String("gitpush-url"),
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
NodeID: String("node"),
}

want := `{
"id": "i",
"description": "description",
"public": true,
"owner": {
"login": "ll",
"id": 123,
"avatar_url": "a",
"gravatar_id": "g",
"name": "n",
"company": "c",
"blog": "b",
"location": "l",
"email": "e",
"hireable": true,
"public_repos": 1,
"followers": 1,
"following": 1,
"created_at": ` + referenceTimeStr + `,
"url": "u"
},
"files": {
"gistfile.py": {
"size": 167,
"filename": "gistfile.py",
"language": "Python",
"type": "application/x-python",
"raw_url": "raw-url",
"content": "c"
}
},
"comments": 1,
"html_url": "html-url",
"git_pull_url": "gitpull-url",
"git_push_url": "gitpush-url",
"created_at": "2010-02-10T10:10:00Z",
"updated_at": "2010-02-10T10:10:00Z",
"node_id": "node"
}`

testJSONMarshal(t, u, want)
}

func TestGistCommit_marshall(t *testing.T) {
testJSONMarshal(t, &GistCommit{}, "{}")

u := &GistCommit{
URL: String("u"),
Version: String("v"),
User: &User{
Login: String("ll"),
ID: Int64(123),
AvatarURL: String("a"),
GravatarID: String("g"),
Name: String("n"),
Company: String("c"),
Blog: String("b"),
Location: String("l"),
Email: String("e"),
Hireable: Bool(true),
PublicRepos: Int(1),
Followers: Int(1),
Following: Int(1),
CreatedAt: &Timestamp{referenceTime},
URL: String("u"),
},
ChangeStatus: &CommitStats{
Additions: Int(1),
Deletions: Int(1),
Total: Int(2),
},
CommittedAt: &Timestamp{referenceTime},
NodeID: String("node"),
}

want := `{
"url": "u",
"version": "v",
"user": {
"login": "ll",
"id": 123,
"avatar_url": "a",
"gravatar_id": "g",
"name": "n",
"company": "c",
"blog": "b",
"location": "l",
"email": "e",
"hireable": true,
"public_repos": 1,
"followers": 1,
"following": 1,
"created_at": ` + referenceTimeStr + `,
"url": "u"
},
"change_status": {
"additions": 1,
"deletions": 1,
"total": 2
},
"committed_at": ` + referenceTimeStr + `,
"node_id": "node"
}`

testJSONMarshal(t, u, want)
}

func TestGistFork_marshall(t *testing.T) {
testJSONMarshal(t, &GistFork{}, "{}")

u := &GistFork{
URL: String("u"),
User: &User{
Login: String("ll"),
ID: Int64(123),
AvatarURL: String("a"),
GravatarID: String("g"),
Name: String("n"),
Company: String("c"),
Blog: String("b"),
Location: String("l"),
Email: String("e"),
Hireable: Bool(true),
PublicRepos: Int(1),
Followers: Int(1),
Following: Int(1),
CreatedAt: &Timestamp{referenceTime},
URL: String("u"),
},
ID: String("id"),
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
NodeID: String("node"),
}

want := `{
"url": "u",
"user": {
"login": "ll",
"id": 123,
"avatar_url": "a",
"gravatar_id": "g",
"name": "n",
"company": "c",
"blog": "b",
"location": "l",
"email": "e",
"hireable": true,
"public_repos": 1,
"followers": 1,
"following": 1,
"created_at": ` + referenceTimeStr + `,
"url": "u"
},
"id": "id",
"created_at": ` + referenceTimeStr + `,
"updated_at": ` + referenceTimeStr + `,
"node_id": "node"
}`

testJSONMarshal(t, u, want)
}

func TestGistsService_List_specifiedUser(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down
100 changes: 100 additions & 0 deletions github/pulls_comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,106 @@ import (
"time"
)

func TestPullComments_marshall(t *testing.T) {
testJSONMarshal(t, &PullRequestComment{}, "{}")

createdAt := time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)
updatedAt := time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)
reactions := &Reactions{
TotalCount: Int(1),
PlusOne: Int(1),
MinusOne: Int(0),
Laugh: Int(0),
Confused: Int(0),
Heart: Int(0),
Hooray: Int(0),
URL: String("u"),
}

u := &PullRequestComment{
ID: Int64(10),
InReplyTo: Int64(8),
Body: String("Test comment"),
Path: String("file1.txt"),
DiffHunk: String("@@ -16,33 +16,40 @@ fmt.Println()"),
PullRequestReviewID: Int64(42),
Position: Int(1),
OriginalPosition: Int(4),
CommitID: String("ab"),
OriginalCommitID: String("9c"),
User: &User{
Login: String("ll"),
ID: Int64(123),
AvatarURL: String("a"),
GravatarID: String("g"),
Name: String("n"),
Company: String("c"),
Blog: String("b"),
Location: String("l"),
Email: String("e"),
Hireable: Bool(true),
PublicRepos: Int(1),
Followers: Int(1),
Following: Int(1),
CreatedAt: &Timestamp{referenceTime},
URL: String("u"),
},
Reactions: reactions,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
URL: String("pullrequestcommentUrl"),
HTMLURL: String("pullrequestcommentHTMLUrl"),
PullRequestURL: String("pullrequestcommentPullRequestURL"),
}

want := `{
"id": 10,
"in_reply_to_id": 8,
"body": "Test comment",
"path": "file1.txt",
"diff_hunk": "@@ -16,33 +16,40 @@ fmt.Println()",
"pull_request_review_id": 42,
"position": 1,
"original_position": 4,
"commit_id": "ab",
"original_commit_id": "9c",
"user": {
"login": "ll",
"id": 123,
"avatar_url": "a",
"gravatar_id": "g",
"name": "n",
"company": "c",
"blog": "b",
"location": "l",
"email": "e",
"hireable": true,
"public_repos": 1,
"followers": 1,
"following": 1,
"created_at": ` + referenceTimeStr + `,
"url": "u"
},
"reactions": {
"total_count": 1,
"+1": 1,
"-1": 0,
"laugh": 0,
"confused": 0,
"heart": 0,
"hooray": 0,
"url": "u"
},
"created_at": "2002-02-10T15:30:00Z",
"updated_at": "2002-02-10T15:30:00Z",
"url": "pullrequestcommentUrl",
"html_url": "pullrequestcommentHTMLUrl",
"pull_request_url": "pullrequestcommentPullRequestURL"
}`

testJSONMarshal(t, u, want)
}

func TestPullRequestsService_ListComments_allPulls(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down