diff --git a/github/actions_workflow_jobs_test.go b/github/actions_workflow_jobs_test.go index 97666b3fe70..4062cc5b275 100644 --- a/github/actions_workflow_jobs_test.go +++ b/github/actions_workflow_jobs_test.go @@ -203,3 +203,147 @@ func TestActionsService_GetWorkflowJobLogs_StatusMovedPermanently_followRedirect t.Errorf("Actions.GetWorkflowJobLogs returned %+v, want %+v", url.String(), want) } } + +func TestTaskStep_Marshal(t *testing.T) { + testJSONMarshal(t, &TaskStep{}, "{}") + + u := &TaskStep{ + Name: String("n"), + Status: String("s"), + Conclusion: String("c"), + Number: Int64(1), + StartedAt: &Timestamp{referenceTime}, + CompletedAt: &Timestamp{referenceTime}, + } + + want := `{ + "name": "n", + "status": "s", + "conclusion": "c", + "number": 1, + "started_at": ` + referenceTimeStr + `, + "completed_at": ` + referenceTimeStr + ` + }` + + testJSONMarshal(t, u, want) +} + +func TestWorkflowJob_Marshal(t *testing.T) { + testJSONMarshal(t, &WorkflowJob{}, "{}") + + u := &WorkflowJob{ + ID: Int64(1), + RunID: Int64(1), + RunURL: String("r"), + NodeID: String("n"), + HeadSHA: String("h"), + URL: String("u"), + HTMLURL: String("h"), + Status: String("s"), + Conclusion: String("c"), + StartedAt: &Timestamp{referenceTime}, + CompletedAt: &Timestamp{referenceTime}, + Name: String("n"), + Steps: []*TaskStep{ + { + Name: String("n"), + Status: String("s"), + Conclusion: String("c"), + Number: Int64(1), + StartedAt: &Timestamp{referenceTime}, + CompletedAt: &Timestamp{referenceTime}, + }, + }, + CheckRunURL: String("c"), + } + + want := `{ + "id": 1, + "run_id": 1, + "run_url": "r", + "node_id": "n", + "head_sha": "h", + "url": "u", + "html_url": "h", + "status": "s", + "conclusion": "c", + "started_at": ` + referenceTimeStr + `, + "completed_at": ` + referenceTimeStr + `, + "name": "n", + "steps": [{ + "name": "n", + "status": "s", + "conclusion": "c", + "number": 1, + "started_at": ` + referenceTimeStr + `, + "completed_at": ` + referenceTimeStr + ` + }], + "check_run_url": "c" + }` + + testJSONMarshal(t, u, want) +} + +func TestJobs_Marshal(t *testing.T) { + testJSONMarshal(t, &Jobs{}, "{}") + + u := &Jobs{ + TotalCount: Int(1), + Jobs: []*WorkflowJob{ + { + ID: Int64(1), + RunID: Int64(1), + RunURL: String("r"), + NodeID: String("n"), + HeadSHA: String("h"), + URL: String("u"), + HTMLURL: String("h"), + Status: String("s"), + Conclusion: String("c"), + StartedAt: &Timestamp{referenceTime}, + CompletedAt: &Timestamp{referenceTime}, + Name: String("n"), + Steps: []*TaskStep{ + { + Name: String("n"), + Status: String("s"), + Conclusion: String("c"), + Number: Int64(1), + StartedAt: &Timestamp{referenceTime}, + CompletedAt: &Timestamp{referenceTime}, + }, + }, + CheckRunURL: String("c"), + }, + }, + } + + want := `{ + "total_count": 1, + "jobs": [{ + "id": 1, + "run_id": 1, + "run_url": "r", + "node_id": "n", + "head_sha": "h", + "url": "u", + "html_url": "h", + "status": "s", + "conclusion": "c", + "started_at": ` + referenceTimeStr + `, + "completed_at": ` + referenceTimeStr + `, + "name": "n", + "steps": [{ + "name": "n", + "status": "s", + "conclusion": "c", + "number": 1, + "started_at": ` + referenceTimeStr + `, + "completed_at": ` + referenceTimeStr + ` + }], + "check_run_url": "c" + }] + }` + + testJSONMarshal(t, u, want) +}