Skip to content

Commit 5158bb8

Browse files
authored
chore: Improve testJSONMarshal (#4042)
1 parent cc0abe8 commit 5158bb8

47 files changed

Lines changed: 399 additions & 376 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

github/actions_cache_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ func TestActionsCache_Marshal(t *testing.T) {
545545

546546
func TestActionsCacheList_Marshal(t *testing.T) {
547547
t.Parallel()
548-
testJSONMarshal(t, &ActionsCacheList{}, "{}")
548+
testJSONMarshal(t, &ActionsCacheList{}, `{"total_count":0}`)
549549

550550
u := &ActionsCacheList{
551551
TotalCount: 2,
@@ -590,7 +590,11 @@ func TestActionsCacheList_Marshal(t *testing.T) {
590590

591591
func TestActionsCacheUsage_Marshal(t *testing.T) {
592592
t.Parallel()
593-
testJSONMarshal(t, &ActionsCacheUsage{}, "{}")
593+
testJSONMarshal(t, &ActionsCacheUsage{}, `{
594+
"active_caches_count": 0,
595+
"active_caches_size_in_bytes": 0,
596+
"full_name": ""
597+
}`)
594598

595599
u := &ActionsCacheUsage{
596600
FullName: "cache_usage1",
@@ -609,7 +613,7 @@ func TestActionsCacheUsage_Marshal(t *testing.T) {
609613

610614
func TestActionsCacheUsageList_Marshal(t *testing.T) {
611615
t.Parallel()
612-
testJSONMarshal(t, &ActionsCacheUsageList{}, "{}")
616+
testJSONMarshal(t, &ActionsCacheUsageList{}, `{"total_count": 0}`)
613617

614618
u := &ActionsCacheUsageList{
615619
TotalCount: 1,
@@ -636,7 +640,10 @@ func TestActionsCacheUsageList_Marshal(t *testing.T) {
636640

637641
func TestTotalCacheUsage_Marshal(t *testing.T) {
638642
t.Parallel()
639-
testJSONMarshal(t, &TotalCacheUsage{}, "{}")
643+
testJSONMarshal(t, &TotalCacheUsage{}, `{
644+
"total_active_caches_count": 0,
645+
"total_active_caches_size_in_bytes": 0
646+
}`)
640647

641648
u := &TotalCacheUsage{
642649
TotalActiveCachesUsageSizeInBytes: 2,

github/actions_runner_groups_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ func TestRunnerGroup_Marshal(t *testing.T) {
554554
Inherited: Ptr(true),
555555
AllowsPublicRepositories: Ptr(true),
556556
RestrictedToWorkflows: Ptr(false),
557-
SelectedWorkflows: []string{},
558557
}
559558

560559
want := `{
@@ -568,16 +567,18 @@ func TestRunnerGroup_Marshal(t *testing.T) {
568567
"network_configuration_id": "nc",
569568
"inherited": true,
570569
"allows_public_repositories": true,
571-
"restricted_to_workflows": false,
572-
"selected_workflows": []
570+
"restricted_to_workflows": false
573571
}`
574572

575573
testJSONMarshal(t, u, want)
576574
}
577575

578576
func TestRunnerGroups_Marshal(t *testing.T) {
579577
t.Parallel()
580-
testJSONMarshal(t, &RunnerGroups{}, "{}")
578+
testJSONMarshal(t, &RunnerGroups{}, `{
579+
"total_count": 0,
580+
"runner_groups": null
581+
}`)
581582

582583
u := &RunnerGroups{
583584
TotalCount: int(1),
@@ -594,7 +595,6 @@ func TestRunnerGroups_Marshal(t *testing.T) {
594595
Inherited: Ptr(true),
595596
AllowsPublicRepositories: Ptr(true),
596597
RestrictedToWorkflows: Ptr(false),
597-
SelectedWorkflows: []string{},
598598
},
599599
},
600600
}
@@ -612,8 +612,7 @@ func TestRunnerGroups_Marshal(t *testing.T) {
612612
"network_configuration_id": "nc",
613613
"inherited": true,
614614
"allows_public_repositories": true,
615-
"restricted_to_workflows": false,
616-
"selected_workflows": []
615+
"restricted_to_workflows": false
617616
}]
618617
}`
619618

@@ -658,7 +657,6 @@ func TestUpdateRunnerGroupRequest_Marshal(t *testing.T) {
658657
Visibility: Ptr("v"),
659658
AllowsPublicRepositories: Ptr(true),
660659
RestrictedToWorkflows: Ptr(false),
661-
SelectedWorkflows: []string{},
662660
NetworkConfigurationID: Ptr("nc"),
663661
}
664662

@@ -667,7 +665,6 @@ func TestUpdateRunnerGroupRequest_Marshal(t *testing.T) {
667665
"visibility": "v",
668666
"allows_public_repositories": true,
669667
"restricted_to_workflows": false,
670-
"selected_workflows": [],
671668
"network_configuration_id": "nc"
672669
}`
673670

@@ -676,7 +673,7 @@ func TestUpdateRunnerGroupRequest_Marshal(t *testing.T) {
676673

677674
func TestSetRepoAccessRunnerGroupRequest_Marshal(t *testing.T) {
678675
t.Parallel()
679-
testJSONMarshal(t, &SetRepoAccessRunnerGroupRequest{}, "{}")
676+
testJSONMarshal(t, &SetRepoAccessRunnerGroupRequest{}, `{"selected_repository_ids": null}`)
680677

681678
u := &SetRepoAccessRunnerGroupRequest{
682679
SelectedRepositoryIDs: []int64{1},
@@ -691,7 +688,7 @@ func TestSetRepoAccessRunnerGroupRequest_Marshal(t *testing.T) {
691688

692689
func TestSetRunnerGroupRunnersRequest_Marshal(t *testing.T) {
693690
t.Parallel()
694-
testJSONMarshal(t, &SetRunnerGroupRunnersRequest{}, "{}")
691+
testJSONMarshal(t, &SetRunnerGroupRunnersRequest{}, `{"runners": null}`)
695692

696693
u := &SetRunnerGroupRunnersRequest{
697694
Runners: []int64{1},

github/actions_runners_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,10 @@ func TestRunnerApplicationDownload_Marshal(t *testing.T) {
580580

581581
func TestActionsEnabledOnOrgRepos_Marshal(t *testing.T) {
582582
t.Parallel()
583-
testJSONMarshal(t, &ActionsEnabledOnOrgRepos{}, "{}")
583+
testJSONMarshal(t, &ActionsEnabledOnOrgRepos{}, `{
584+
"repositories": null,
585+
"total_count": 0
586+
}`)
584587

585588
u := &ActionsEnabledOnOrgRepos{
586589
TotalCount: 1,
@@ -682,7 +685,10 @@ func TestRunner_Marshal(t *testing.T) {
682685

683686
func TestRunners_Marshal(t *testing.T) {
684687
t.Parallel()
685-
testJSONMarshal(t, &Runners{}, "{}")
688+
testJSONMarshal(t, &Runners{}, `{
689+
"runners": null,
690+
"total_count": 0
691+
}`)
686692

687693
u := &Runners{
688694
TotalCount: 1,

github/actions_secrets_test.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,10 @@ func TestActionsService_DeleteEnvSecret(t *testing.T) {
877877

878878
func TestPublicKey_Marshal(t *testing.T) {
879879
t.Parallel()
880-
testJSONMarshal(t, &PublicKey{}, "{}")
880+
testJSONMarshal(t, &PublicKey{}, `{
881+
"key": null,
882+
"key_id": null
883+
}`)
881884

882885
u := &PublicKey{
883886
KeyID: Ptr("kid"),
@@ -894,7 +897,11 @@ func TestPublicKey_Marshal(t *testing.T) {
894897

895898
func TestSecret_Marshal(t *testing.T) {
896899
t.Parallel()
897-
testJSONMarshal(t, &Secret{}, "{}")
900+
testJSONMarshal(t, &Secret{}, `{
901+
"name": "",
902+
"created_at": "0001-01-01T00:00:00Z",
903+
"updated_at": "0001-01-01T00:00:00Z"
904+
}`)
898905

899906
u := &Secret{
900907
Name: "n",
@@ -917,7 +924,10 @@ func TestSecret_Marshal(t *testing.T) {
917924

918925
func TestSecrets_Marshal(t *testing.T) {
919926
t.Parallel()
920-
testJSONMarshal(t, &Secrets{}, "{}")
927+
testJSONMarshal(t, &Secrets{}, `{
928+
"total_count": 0,
929+
"secrets": null
930+
}`)
921931

922932
u := &Secrets{
923933
TotalCount: 1,
@@ -950,7 +960,10 @@ func TestSecrets_Marshal(t *testing.T) {
950960

951961
func TestEncryptedSecret_Marshal(t *testing.T) {
952962
t.Parallel()
953-
testJSONMarshal(t, &EncryptedSecret{}, "{}")
963+
testJSONMarshal(t, &EncryptedSecret{}, `{
964+
"key_id": "",
965+
"encrypted_value": ""
966+
}`)
954967

955968
u := &EncryptedSecret{
956969
Name: "n",
@@ -967,7 +980,7 @@ func TestEncryptedSecret_Marshal(t *testing.T) {
967980
"selected_repository_ids": [1]
968981
}`
969982

970-
testJSONMarshal(t, u, want)
983+
testJSONMarshal(t, u, want, cmpIgnoreFieldOption("Name"))
971984
}
972985

973986
func TestSelectedReposList_Marshal(t *testing.T) {

github/actions_variables_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,10 @@ func TestActionsService_DeleteEnvVariable(t *testing.T) {
730730

731731
func TestActionVariable_Marshal(t *testing.T) {
732732
t.Parallel()
733-
testJSONMarshal(t, &ActionsVariable{}, "{}")
733+
testJSONMarshal(t, &ActionsVariable{}, `{
734+
"name": "",
735+
"value": ""
736+
}`)
734737

735738
av := &ActionsVariable{
736739
Name: "n",

github/actions_workflow_runs_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,11 @@ func TestActionsService_ReviewCustomDeploymentProtectionRule(t *testing.T) {
889889

890890
func TestReviewCustomDeploymentProtectionRuleRequest_Marshal(t *testing.T) {
891891
t.Parallel()
892-
testJSONMarshal(t, &ReviewCustomDeploymentProtectionRuleRequest{}, "{}")
892+
testJSONMarshal(t, &ReviewCustomDeploymentProtectionRuleRequest{}, `{
893+
"comment": "",
894+
"environment_name": "",
895+
"state": ""
896+
}`)
893897

894898
r := &ReviewCustomDeploymentProtectionRuleRequest{
895899
EnvironmentName: "e",

github/actions_workflows_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ func TestWorkflowUsage_Marshal(t *testing.T) {
715715

716716
func TestCreateWorkflowDispatchEventRequest_Marshal(t *testing.T) {
717717
t.Parallel()
718-
testJSONMarshal(t, &CreateWorkflowDispatchEventRequest{}, "{}")
718+
testJSONMarshal(t, &CreateWorkflowDispatchEventRequest{}, `{"ref": ""}`)
719719

720720
inputs := make(map[string]any, 0)
721721
inputs["key"] = "value"

github/activity_notifications_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func TestNotificationSubject_Marshal(t *testing.T) {
446446

447447
func TestMarkReadOptions_Marshal(t *testing.T) {
448448
t.Parallel()
449-
testJSONMarshal(t, &markReadOptions{}, "{}")
449+
testJSONMarshal(t, &markReadOptions{}, `{}`)
450450

451451
u := &markReadOptions{
452452
LastReadAt: Timestamp{referenceTime},

github/admin_users_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func TestUserImpersonation_Delete(t *testing.T) {
185185

186186
func TestCreateUserRequest_Marshal(t *testing.T) {
187187
t.Parallel()
188-
testJSONMarshal(t, &CreateUserRequest{}, "{}")
188+
testJSONMarshal(t, &CreateUserRequest{}, `{"login": ""}`)
189189

190190
u := &CreateUserRequest{
191191
Login: "l",

github/apps_installation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestAppsService_RevokeInstallationToken(t *testing.T) {
162162

163163
func TestListRepositories_Marshal(t *testing.T) {
164164
t.Parallel()
165-
testJSONMarshal(t, &ListRepositories{}, "{}")
165+
testJSONMarshal(t, &ListRepositories{}, `{"repositories": null}`)
166166

167167
u := &ListRepositories{
168168
TotalCount: Ptr(1),

0 commit comments

Comments
 (0)