From 75e2ff78a2269feb0e80338bb6fa3f7a996c821b Mon Sep 17 00:00:00 2001 From: sagar23sj Date: Sat, 17 Jul 2021 22:49:01 +0530 Subject: [PATCH] Resources Covered: - Deployment - DeploymentRequest - DeploymentStatus - DeploymentStatusRequest --- github/repos_deployments_test.go | 213 +++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) diff --git a/github/repos_deployments_test.go b/github/repos_deployments_test.go index 2e12ec6fe13..c3d6637e37f 100644 --- a/github/repos_deployments_test.go +++ b/github/repos_deployments_test.go @@ -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) +}