Skip to content

Commit

Permalink
Add test cases for JSON resource marshaling (#2014)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagar23sj authored Jul 17, 2021
1 parent 4cbd718 commit 656792c
Showing 1 changed file with 213 additions and 0 deletions.
213 changes: 213 additions & 0 deletions github/repos_deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,216 @@ func TestRepositoriesService_CreateDeploymentStatus(t *testing.T) {
return resp, err
})
}

func TestDeploymentStatusRequest_Marshal(t *testing.T) {
testJSONMarshal(t, &DeploymentStatusRequest{}, "{}")

r := &DeploymentStatusRequest{
State: String("state"),
LogURL: String("logurl"),
Description: String("desc"),
Environment: String("env"),
EnvironmentURL: String("eurl"),
AutoInactive: Bool(false),
}

want := `{
"state": "state",
"log_url": "logurl",
"description": "desc",
"environment": "env",
"environment_url": "eurl",
"auto_inactive": false
}`

testJSONMarshal(t, r, want)
}

func TestDeploymentStatus_Marshal(t *testing.T) {
testJSONMarshal(t, &DeploymentStatus{}, "{}")

r := &DeploymentStatus{
ID: Int64(1),
State: String("state"),
Creator: &User{
Login: String("l"),
ID: Int64(1),
URL: String("u"),
AvatarURL: String("a"),
GravatarID: String("g"),
Name: String("n"),
Company: String("c"),
Blog: String("b"),
Location: String("l"),
Email: String("e"),
Hireable: Bool(true),
Bio: String("b"),
TwitterUsername: String("t"),
PublicRepos: Int(1),
Followers: Int(1),
Following: Int(1),
CreatedAt: &Timestamp{referenceTime},
SuspendedAt: &Timestamp{referenceTime},
},
Description: String("desc"),
Environment: String("env"),
NodeID: String("nid"),
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
TargetURL: String("turl"),
DeploymentURL: String("durl"),
RepositoryURL: String("rurl"),
EnvironmentURL: String("eurl"),
LogURL: String("lurl"),
URL: String("url"),
}

want := `{
"id": 1,
"state": "state",
"creator": {
"login": "l",
"id": 1,
"avatar_url": "a",
"gravatar_id": "g",
"name": "n",
"company": "c",
"blog": "b",
"location": "l",
"email": "e",
"hireable": true,
"bio": "b",
"twitter_username": "t",
"public_repos": 1,
"followers": 1,
"following": 1,
"created_at": ` + referenceTimeStr + `,
"suspended_at": ` + referenceTimeStr + `,
"url": "u"
},
"description": "desc",
"environment": "env",
"node_id": "nid",
"created_at": ` + referenceTimeStr + `,
"updated_at": ` + referenceTimeStr + `,
"target_url": "turl",
"deployment_url": "durl",
"repository_url": "rurl",
"environment_url": "eurl",
"log_url": "lurl",
"url": "url"
}`

testJSONMarshal(t, r, want)
}

func TestDeploymentRequest_Marshal(t *testing.T) {
testJSONMarshal(t, &DeploymentRequest{}, "{}")

r := &DeploymentRequest{
Ref: String("ref"),
Task: String("task"),
AutoMerge: Bool(false),
RequiredContexts: &[]string{"s"},
Payload: "payload",
Environment: String("environment"),
Description: String("description"),
TransientEnvironment: Bool(false),
ProductionEnvironment: Bool(false),
}

want := `{
"ref": "ref",
"task": "task",
"auto_merge": false,
"required_contexts": ["s"],
"payload": "payload",
"environment": "environment",
"description": "description",
"transient_environment": false,
"production_environment": false
}`

testJSONMarshal(t, r, want)
}

func TestDeployment_Marshal(t *testing.T) {
testJSONMarshal(t, &Deployment{}, "{}")

str := "s"
jsonMsg, _ := json.Marshal(str)

r := &Deployment{
URL: String("url"),
ID: Int64(1),
SHA: String("sha"),
Ref: String("ref"),
Task: String("task"),
Payload: jsonMsg,
Environment: String("env"),
Description: String("desc"),
Creator: &User{
Login: String("l"),
ID: Int64(1),
URL: String("u"),
AvatarURL: String("a"),
GravatarID: String("g"),
Name: String("n"),
Company: String("c"),
Blog: String("b"),
Location: String("l"),
Email: String("e"),
Hireable: Bool(true),
Bio: String("b"),
TwitterUsername: String("t"),
PublicRepos: Int(1),
Followers: Int(1),
Following: Int(1),
CreatedAt: &Timestamp{referenceTime},
SuspendedAt: &Timestamp{referenceTime},
},
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
StatusesURL: String("surl"),
RepositoryURL: String("rurl"),
NodeID: String("nid"),
}

want := `{
"url": "url",
"id": 1,
"sha": "sha",
"ref": "ref",
"task": "task",
"payload": "s",
"environment": "env",
"description": "desc",
"creator": {
"login": "l",
"id": 1,
"avatar_url": "a",
"gravatar_id": "g",
"name": "n",
"company": "c",
"blog": "b",
"location": "l",
"email": "e",
"hireable": true,
"bio": "b",
"twitter_username": "t",
"public_repos": 1,
"followers": 1,
"following": 1,
"created_at": ` + referenceTimeStr + `,
"suspended_at": ` + referenceTimeStr + `,
"url": "u"
},
"created_at": ` + referenceTimeStr + `,
"updated_at": ` + referenceTimeStr + `,
"statuses_url": "surl",
"repository_url": "rurl",
"node_id": "nid"
}`

testJSONMarshal(t, r, want)
}

0 comments on commit 656792c

Please sign in to comment.