Skip to content

Commit d15bdce

Browse files
authored
Add test cases for JSON resource marshaling (#1909)
1 parent 4a83d0e commit d15bdce

File tree

1 file changed

+184
-0
lines changed

1 file changed

+184
-0
lines changed

github/actions_runners_test.go

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,187 @@ func TestActionsService_RemoveOrganizationRunner(t *testing.T) {
500500
return client.Actions.RemoveOrganizationRunner(ctx, "o", 21)
501501
})
502502
}
503+
504+
func TestRunnerApplicationDownload_Marshal(t *testing.T) {
505+
testJSONMarshal(t, &RunnerApplicationDownload{}, "{}")
506+
507+
u := &RunnerApplicationDownload{
508+
OS: String("o"),
509+
Architecture: String("a"),
510+
DownloadURL: String("d"),
511+
Filename: String("f"),
512+
TempDownloadToken: String("t"),
513+
SHA256Checksum: String("s"),
514+
}
515+
516+
want := `{
517+
"os": "o",
518+
"architecture": "a",
519+
"download_url": "d",
520+
"filename": "f",
521+
"temp_download_token": "t",
522+
"sha256_checksum": "s"
523+
}`
524+
525+
testJSONMarshal(t, u, want)
526+
}
527+
528+
func TestActionsEnabledOnOrgRepos_Marshal(t *testing.T) {
529+
testJSONMarshal(t, &ActionsEnabledOnOrgRepos{}, "{}")
530+
531+
u := &ActionsEnabledOnOrgRepos{
532+
TotalCount: 1,
533+
Repositories: []*Repository{
534+
{
535+
ID: Int64(1),
536+
URL: String("u"),
537+
Name: String("n"),
538+
},
539+
},
540+
}
541+
542+
want := `{
543+
"total_count": 1,
544+
"repositories": [
545+
{
546+
"id": 1,
547+
"url": "u",
548+
"name": "n"
549+
}
550+
]
551+
}`
552+
553+
testJSONMarshal(t, u, want)
554+
}
555+
556+
func TestRegistrationToken_Marshal(t *testing.T) {
557+
testJSONMarshal(t, &RegistrationToken{}, "{}")
558+
559+
u := &RegistrationToken{
560+
Token: String("t"),
561+
ExpiresAt: &Timestamp{referenceTime},
562+
}
563+
564+
want := `{
565+
"token": "t",
566+
"expires_at": ` + referenceTimeStr + `
567+
}`
568+
569+
testJSONMarshal(t, u, want)
570+
}
571+
572+
func TestRunnerLabels_Marshal(t *testing.T) {
573+
testJSONMarshal(t, &RunnerLabels{}, "{}")
574+
575+
u := &RunnerLabels{
576+
ID: Int64(1),
577+
Name: String("n"),
578+
Type: String("t"),
579+
}
580+
581+
want := `{
582+
"id": 1,
583+
"name": "n",
584+
"type": "t"
585+
}`
586+
587+
testJSONMarshal(t, u, want)
588+
}
589+
590+
func TestRunner_Marshal(t *testing.T) {
591+
testJSONMarshal(t, &Runner{}, "{}")
592+
593+
u := &Runner{
594+
ID: Int64(1),
595+
Name: String("n"),
596+
OS: String("o"),
597+
Status: String("s"),
598+
Busy: Bool(false),
599+
Labels: []*RunnerLabels{
600+
{
601+
ID: Int64(1),
602+
Name: String("n"),
603+
Type: String("t"),
604+
},
605+
},
606+
}
607+
608+
want := `{
609+
"id": 1,
610+
"name": "n",
611+
"os": "o",
612+
"status": "s",
613+
"busy": false,
614+
"labels": [
615+
{
616+
"id": 1,
617+
"name": "n",
618+
"type": "t"
619+
}
620+
]
621+
}`
622+
623+
testJSONMarshal(t, u, want)
624+
}
625+
626+
func TestRunners_Marshal(t *testing.T) {
627+
testJSONMarshal(t, &Runners{}, "{}")
628+
629+
u := &Runners{
630+
TotalCount: 1,
631+
Runners: []*Runner{
632+
{
633+
ID: Int64(1),
634+
Name: String("n"),
635+
OS: String("o"),
636+
Status: String("s"),
637+
Busy: Bool(false),
638+
Labels: []*RunnerLabels{
639+
{
640+
ID: Int64(1),
641+
Name: String("n"),
642+
Type: String("t"),
643+
},
644+
},
645+
},
646+
},
647+
}
648+
649+
want := `{
650+
"total_count": 1,
651+
"runners": [
652+
{
653+
"id": 1,
654+
"name": "n",
655+
"os": "o",
656+
"status": "s",
657+
"busy": false,
658+
"labels": [
659+
{
660+
"id": 1,
661+
"name": "n",
662+
"type": "t"
663+
}
664+
]
665+
}
666+
]
667+
}`
668+
669+
testJSONMarshal(t, u, want)
670+
}
671+
672+
func TestRemoveToken_Marshal(t *testing.T) {
673+
testJSONMarshal(t, &RemoveToken{}, "{}")
674+
675+
u := &RemoveToken{
676+
Token: String("t"),
677+
ExpiresAt: &Timestamp{referenceTime},
678+
}
679+
680+
want := `{
681+
"token": "t",
682+
"expires_at": ` + referenceTimeStr + `
683+
}`
684+
685+
testJSONMarshal(t, u, want)
686+
}

0 commit comments

Comments
 (0)