+
Skip to content

Add test cases for JSON resource marshaling #1973

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

Merged
merged 1 commit into from
Jul 13, 2021
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
164 changes: 164 additions & 0 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2020,3 +2020,167 @@ type roundTripperFunc func(*http.Request) (*http.Response, error)
func (fn roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
return fn(r)
}

func TestErrorResponse_Marshal(t *testing.T) {
testJSONMarshal(t, &ErrorResponse{}, "{}")

u := &ErrorResponse{
Message: "msg",
Errors: []Error{
{
Resource: "res",
Field: "f",
Code: "c",
Message: "msg",
},
},
Block: &ErrorBlock{
Reason: "reason",
CreatedAt: &Timestamp{referenceTime},
},
DocumentationURL: "doc",
}

want := `{
"message": "msg",
"errors": [
{
"resource": "res",
"field": "f",
"code": "c",
"message": "msg"
}
],
"block": {
"reason": "reason",
"created_at": ` + referenceTimeStr + `
},
"documentation_url": "doc"
}`

testJSONMarshal(t, u, want)
}

func TestErrorBlock_Marshal(t *testing.T) {
testJSONMarshal(t, &ErrorBlock{}, "{}")

u := &ErrorBlock{
Reason: "reason",
CreatedAt: &Timestamp{referenceTime},
}

want := `{
"reason": "reason",
"created_at": ` + referenceTimeStr + `
}`

testJSONMarshal(t, u, want)
}

func TestRateLimitError_Marshal(t *testing.T) {
testJSONMarshal(t, &RateLimitError{}, "{}")

u := &RateLimitError{
Rate: Rate{
Limit: 1,
Remaining: 1,
Reset: Timestamp{referenceTime},
},
Message: "msg",
}

want := `{
"Rate": {
"limit": 1,
"remaining": 1,
"reset": ` + referenceTimeStr + `
},
"message": "msg"
}`

testJSONMarshal(t, u, want)
}

func TestAbuseRateLimitError_Marshal(t *testing.T) {
testJSONMarshal(t, &AbuseRateLimitError{}, "{}")

u := &AbuseRateLimitError{
Message: "msg",
}

want := `{
"message": "msg"
}`

testJSONMarshal(t, u, want)
}

func TestError_Marshal(t *testing.T) {
testJSONMarshal(t, &Error{}, "{}")

u := &Error{
Resource: "res",
Field: "field",
Code: "code",
Message: "msg",
}

want := `{
"resource": "res",
"field": "field",
"code": "code",
"message": "msg"
}`

testJSONMarshal(t, u, want)
}

func TestRate_Marshal(t *testing.T) {
testJSONMarshal(t, &Rate{}, "{}")

u := &Rate{
Limit: 1,
Remaining: 1,
Reset: Timestamp{referenceTime},
}

want := `{
"limit": 1,
"remaining": 1,
"reset": ` + referenceTimeStr + `
}`

testJSONMarshal(t, u, want)
}

func TestRateLimits_Marshal(t *testing.T) {
testJSONMarshal(t, &RateLimits{}, "{}")

u := &RateLimits{
Core: &Rate{
Limit: 1,
Remaining: 1,
Reset: Timestamp{referenceTime},
},
Search: &Rate{
Limit: 1,
Remaining: 1,
Reset: Timestamp{referenceTime},
},
}

want := `{
"core": {
"limit": 1,
"remaining": 1,
"reset": ` + referenceTimeStr + `
},
"search": {
"limit": 1,
"remaining": 1,
"reset": ` + referenceTimeStr + `
}
}`

testJSONMarshal(t, u, want)
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载