diff --git a/github/actions_cache_test.go b/github/actions_cache_test.go index ef3cd53fded..8f31e154e48 100644 --- a/github/actions_cache_test.go +++ b/github/actions_cache_test.go @@ -545,7 +545,7 @@ func TestActionsCache_Marshal(t *testing.T) { func TestActionsCacheList_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &ActionsCacheList{}, "{}") + testJSONMarshal(t, &ActionsCacheList{}, `{"total_count":0}`) u := &ActionsCacheList{ TotalCount: 2, @@ -590,7 +590,11 @@ func TestActionsCacheList_Marshal(t *testing.T) { func TestActionsCacheUsage_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &ActionsCacheUsage{}, "{}") + testJSONMarshal(t, &ActionsCacheUsage{}, `{ + "active_caches_count": 0, + "active_caches_size_in_bytes": 0, + "full_name": "" + }`) u := &ActionsCacheUsage{ FullName: "cache_usage1", @@ -609,7 +613,7 @@ func TestActionsCacheUsage_Marshal(t *testing.T) { func TestActionsCacheUsageList_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &ActionsCacheUsageList{}, "{}") + testJSONMarshal(t, &ActionsCacheUsageList{}, `{"total_count": 0}`) u := &ActionsCacheUsageList{ TotalCount: 1, @@ -636,7 +640,10 @@ func TestActionsCacheUsageList_Marshal(t *testing.T) { func TestTotalCacheUsage_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &TotalCacheUsage{}, "{}") + testJSONMarshal(t, &TotalCacheUsage{}, `{ + "total_active_caches_count": 0, + "total_active_caches_size_in_bytes": 0 + }`) u := &TotalCacheUsage{ TotalActiveCachesUsageSizeInBytes: 2, diff --git a/github/actions_runner_groups_test.go b/github/actions_runner_groups_test.go index c5c83001457..994e2716b4c 100644 --- a/github/actions_runner_groups_test.go +++ b/github/actions_runner_groups_test.go @@ -554,7 +554,6 @@ func TestRunnerGroup_Marshal(t *testing.T) { Inherited: Ptr(true), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(false), - SelectedWorkflows: []string{}, } want := `{ @@ -568,8 +567,7 @@ func TestRunnerGroup_Marshal(t *testing.T) { "network_configuration_id": "nc", "inherited": true, "allows_public_repositories": true, - "restricted_to_workflows": false, - "selected_workflows": [] + "restricted_to_workflows": false }` testJSONMarshal(t, u, want) @@ -577,7 +575,10 @@ func TestRunnerGroup_Marshal(t *testing.T) { func TestRunnerGroups_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &RunnerGroups{}, "{}") + testJSONMarshal(t, &RunnerGroups{}, `{ + "total_count": 0, + "runner_groups": null + }`) u := &RunnerGroups{ TotalCount: int(1), @@ -594,7 +595,6 @@ func TestRunnerGroups_Marshal(t *testing.T) { Inherited: Ptr(true), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(false), - SelectedWorkflows: []string{}, }, }, } @@ -612,8 +612,7 @@ func TestRunnerGroups_Marshal(t *testing.T) { "network_configuration_id": "nc", "inherited": true, "allows_public_repositories": true, - "restricted_to_workflows": false, - "selected_workflows": [] + "restricted_to_workflows": false }] }` @@ -658,7 +657,6 @@ func TestUpdateRunnerGroupRequest_Marshal(t *testing.T) { Visibility: Ptr("v"), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(false), - SelectedWorkflows: []string{}, NetworkConfigurationID: Ptr("nc"), } @@ -667,7 +665,6 @@ func TestUpdateRunnerGroupRequest_Marshal(t *testing.T) { "visibility": "v", "allows_public_repositories": true, "restricted_to_workflows": false, - "selected_workflows": [], "network_configuration_id": "nc" }` @@ -676,7 +673,7 @@ func TestUpdateRunnerGroupRequest_Marshal(t *testing.T) { func TestSetRepoAccessRunnerGroupRequest_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &SetRepoAccessRunnerGroupRequest{}, "{}") + testJSONMarshal(t, &SetRepoAccessRunnerGroupRequest{}, `{"selected_repository_ids": null}`) u := &SetRepoAccessRunnerGroupRequest{ SelectedRepositoryIDs: []int64{1}, @@ -691,7 +688,7 @@ func TestSetRepoAccessRunnerGroupRequest_Marshal(t *testing.T) { func TestSetRunnerGroupRunnersRequest_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &SetRunnerGroupRunnersRequest{}, "{}") + testJSONMarshal(t, &SetRunnerGroupRunnersRequest{}, `{"runners": null}`) u := &SetRunnerGroupRunnersRequest{ Runners: []int64{1}, diff --git a/github/actions_runners_test.go b/github/actions_runners_test.go index 3624fb35aa7..323610fbe45 100644 --- a/github/actions_runners_test.go +++ b/github/actions_runners_test.go @@ -580,7 +580,10 @@ func TestRunnerApplicationDownload_Marshal(t *testing.T) { func TestActionsEnabledOnOrgRepos_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &ActionsEnabledOnOrgRepos{}, "{}") + testJSONMarshal(t, &ActionsEnabledOnOrgRepos{}, `{ + "repositories": null, + "total_count": 0 + }`) u := &ActionsEnabledOnOrgRepos{ TotalCount: 1, @@ -682,7 +685,10 @@ func TestRunner_Marshal(t *testing.T) { func TestRunners_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &Runners{}, "{}") + testJSONMarshal(t, &Runners{}, `{ + "runners": null, + "total_count": 0 + }`) u := &Runners{ TotalCount: 1, diff --git a/github/actions_secrets_test.go b/github/actions_secrets_test.go index 7dc499e56fc..099bad6415d 100644 --- a/github/actions_secrets_test.go +++ b/github/actions_secrets_test.go @@ -877,7 +877,10 @@ func TestActionsService_DeleteEnvSecret(t *testing.T) { func TestPublicKey_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &PublicKey{}, "{}") + testJSONMarshal(t, &PublicKey{}, `{ + "key": null, + "key_id": null + }`) u := &PublicKey{ KeyID: Ptr("kid"), @@ -894,7 +897,11 @@ func TestPublicKey_Marshal(t *testing.T) { func TestSecret_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &Secret{}, "{}") + testJSONMarshal(t, &Secret{}, `{ + "name": "", + "created_at": "0001-01-01T00:00:00Z", + "updated_at": "0001-01-01T00:00:00Z" + }`) u := &Secret{ Name: "n", @@ -917,7 +924,10 @@ func TestSecret_Marshal(t *testing.T) { func TestSecrets_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &Secrets{}, "{}") + testJSONMarshal(t, &Secrets{}, `{ + "total_count": 0, + "secrets": null + }`) u := &Secrets{ TotalCount: 1, @@ -950,7 +960,10 @@ func TestSecrets_Marshal(t *testing.T) { func TestEncryptedSecret_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &EncryptedSecret{}, "{}") + testJSONMarshal(t, &EncryptedSecret{}, `{ + "key_id": "", + "encrypted_value": "" + }`) u := &EncryptedSecret{ Name: "n", @@ -967,7 +980,7 @@ func TestEncryptedSecret_Marshal(t *testing.T) { "selected_repository_ids": [1] }` - testJSONMarshal(t, u, want) + testJSONMarshal(t, u, want, cmpIgnoreFieldOption("Name")) } func TestSelectedReposList_Marshal(t *testing.T) { diff --git a/github/actions_variables_test.go b/github/actions_variables_test.go index 1a47ede0de6..473833a4536 100644 --- a/github/actions_variables_test.go +++ b/github/actions_variables_test.go @@ -730,7 +730,10 @@ func TestActionsService_DeleteEnvVariable(t *testing.T) { func TestActionVariable_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &ActionsVariable{}, "{}") + testJSONMarshal(t, &ActionsVariable{}, `{ + "name": "", + "value": "" + }`) av := &ActionsVariable{ Name: "n", diff --git a/github/actions_workflow_runs_test.go b/github/actions_workflow_runs_test.go index 41a0a14be53..d76712f39ca 100644 --- a/github/actions_workflow_runs_test.go +++ b/github/actions_workflow_runs_test.go @@ -889,7 +889,11 @@ func TestActionsService_ReviewCustomDeploymentProtectionRule(t *testing.T) { func TestReviewCustomDeploymentProtectionRuleRequest_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &ReviewCustomDeploymentProtectionRuleRequest{}, "{}") + testJSONMarshal(t, &ReviewCustomDeploymentProtectionRuleRequest{}, `{ + "comment": "", + "environment_name": "", + "state": "" + }`) r := &ReviewCustomDeploymentProtectionRuleRequest{ EnvironmentName: "e", diff --git a/github/actions_workflows_test.go b/github/actions_workflows_test.go index 594906b269a..0737b5f9393 100644 --- a/github/actions_workflows_test.go +++ b/github/actions_workflows_test.go @@ -715,7 +715,7 @@ func TestWorkflowUsage_Marshal(t *testing.T) { func TestCreateWorkflowDispatchEventRequest_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &CreateWorkflowDispatchEventRequest{}, "{}") + testJSONMarshal(t, &CreateWorkflowDispatchEventRequest{}, `{"ref": ""}`) inputs := make(map[string]any, 0) inputs["key"] = "value" diff --git a/github/activity_notifications_test.go b/github/activity_notifications_test.go index b0d25645ab2..752eb62baa6 100644 --- a/github/activity_notifications_test.go +++ b/github/activity_notifications_test.go @@ -446,7 +446,7 @@ func TestNotificationSubject_Marshal(t *testing.T) { func TestMarkReadOptions_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &markReadOptions{}, "{}") + testJSONMarshal(t, &markReadOptions{}, `{}`) u := &markReadOptions{ LastReadAt: Timestamp{referenceTime}, diff --git a/github/admin_users_test.go b/github/admin_users_test.go index 6c736e87baf..fe3db01ecb2 100644 --- a/github/admin_users_test.go +++ b/github/admin_users_test.go @@ -185,7 +185,7 @@ func TestUserImpersonation_Delete(t *testing.T) { func TestCreateUserRequest_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &CreateUserRequest{}, "{}") + testJSONMarshal(t, &CreateUserRequest{}, `{"login": ""}`) u := &CreateUserRequest{ Login: "l", diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 53f1c837a04..591f6a3d696 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -162,7 +162,7 @@ func TestAppsService_RevokeInstallationToken(t *testing.T) { func TestListRepositories_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &ListRepositories{}, "{}") + testJSONMarshal(t, &ListRepositories{}, `{"repositories": null}`) u := &ListRepositories{ TotalCount: Ptr(1), diff --git a/github/billing_test.go b/github/billing_test.go index 360b674e8d8..db527c37563 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -240,9 +240,13 @@ func TestMinutesUsedBreakdown_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } -func TestPackageBilling_Marshal(t *testing.T) { +func TestPackagesBilling_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &PackagesBilling{}, "{}") + testJSONMarshal(t, &PackagesBilling{}, `{ + "total_gigabytes_bandwidth_used": 0, + "total_paid_gigabytes_bandwidth_used": 0, + "included_gigabytes_bandwidth": 0 + }`) u := &PackagesBilling{ TotalGigabytesBandwidthUsed: 1, @@ -261,7 +265,11 @@ func TestPackageBilling_Marshal(t *testing.T) { func TestStorageBilling_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &StorageBilling{}, "{}") + testJSONMarshal(t, &StorageBilling{}, `{ + "days_left_in_billing_cycle": 0, + "estimated_paid_storage_for_month": 0, + "estimated_storage_for_month": 0 + }`) u := &StorageBilling{ DaysLeftInBillingCycle: 1, diff --git a/github/checks_test.go b/github/checks_test.go index 19cf35df2f0..ab0d699609e 100644 --- a/github/checks_test.go +++ b/github/checks_test.go @@ -1014,7 +1014,11 @@ func TestCheckRunImage_Marshal(t *testing.T) { func TestCheckRunAction_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &CheckRunAction{}, "{}") + testJSONMarshal(t, &CheckRunAction{}, `{ + "label": "", + "description": "", + "identifier": "" + }`) u := &CheckRunAction{ Label: "l", @@ -1050,7 +1054,7 @@ func TestAutoTriggerCheck_Marshal(t *testing.T) { func TestCreateCheckSuiteOptions_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &CreateCheckSuiteOptions{}, "{}") + testJSONMarshal(t, &CreateCheckSuiteOptions{}, `{"head_sha": ""}`) u := &CreateCheckSuiteOptions{ HeadSHA: "hsha", @@ -1130,7 +1134,10 @@ func TestCheckRunOutput_Marshal(t *testing.T) { func TestCreateCheckRunOptions_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &CreateCheckRunOptions{}, "{}") + testJSONMarshal(t, &CreateCheckRunOptions{}, `{ + "name": "", + "head_sha": "" + }`) u := &CreateCheckRunOptions{ Name: "n", @@ -1227,7 +1234,7 @@ func TestCreateCheckRunOptions_Marshal(t *testing.T) { func TestUpdateCheckRunOptions_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &UpdateCheckRunOptions{}, "{}") + testJSONMarshal(t, &UpdateCheckRunOptions{}, `{"name": ""}`) u := &UpdateCheckRunOptions{ Name: "n", diff --git a/github/dependabot_alerts_test.go b/github/dependabot_alerts_test.go index d6ab4d1453a..88a4eb0bbce 100644 --- a/github/dependabot_alerts_test.go +++ b/github/dependabot_alerts_test.go @@ -388,8 +388,7 @@ func TestDependabotSecurityAdvisory_Marshal(t *testing.T) { } ], "published_at": "2018-10-03T21:13:54Z", - "updated_at": "2022-04-26T18:35:37Z", - "withdrawn_at": null + "updated_at": "2022-04-26T18:35:37Z" }` testJSONMarshal(t, h, want) diff --git a/github/enterprise_actions_runner_groups_test.go b/github/enterprise_actions_runner_groups_test.go index 3a42732aa5a..b723ed26257 100644 --- a/github/enterprise_actions_runner_groups_test.go +++ b/github/enterprise_actions_runner_groups_test.go @@ -544,7 +544,6 @@ func TestEnterpriseRunnerGroup_Marshal(t *testing.T) { Inherited: Ptr(true), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(false), - SelectedWorkflows: []string{}, } want := `{ @@ -556,8 +555,7 @@ func TestEnterpriseRunnerGroup_Marshal(t *testing.T) { "runners_url": "r", "inherited": true, "allows_public_repositories": true, - "restricted_to_workflows": false, - "selected_workflows": [] + "restricted_to_workflows": false }` testJSONMarshal(t, u, want) @@ -565,7 +563,7 @@ func TestEnterpriseRunnerGroup_Marshal(t *testing.T) { func TestEnterpriseRunnerGroups_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &EnterpriseRunnerGroups{}, "{}") + testJSONMarshal(t, &EnterpriseRunnerGroups{}, `{"runner_groups": null}`) u := &EnterpriseRunnerGroups{ TotalCount: Ptr(1), @@ -580,7 +578,6 @@ func TestEnterpriseRunnerGroups_Marshal(t *testing.T) { Inherited: Ptr(true), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(false), - SelectedWorkflows: []string{}, }, }, } @@ -596,8 +593,7 @@ func TestEnterpriseRunnerGroups_Marshal(t *testing.T) { "runners_url": "r", "inherited": true, "allows_public_repositories": true, - "restricted_to_workflows": false, - "selected_workflows": [] + "restricted_to_workflows": false }] }` @@ -640,15 +636,13 @@ func TestUpdateEnterpriseRunnerGroupRequest_Marshal(t *testing.T) { Visibility: Ptr("v"), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(false), - SelectedWorkflows: []string{}, } want := `{ "name": "n", "visibility": "v", "allows_public_repositories": true, - "restricted_to_workflows": false, - "selected_workflows": [] + "restricted_to_workflows": false }` testJSONMarshal(t, u, want) @@ -656,7 +650,7 @@ func TestUpdateEnterpriseRunnerGroupRequest_Marshal(t *testing.T) { func TestSetOrgAccessRunnerGroupRequest_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &SetOrgAccessRunnerGroupRequest{}, "{}") + testJSONMarshal(t, &SetOrgAccessRunnerGroupRequest{}, `{"selected_organization_ids": null}`) u := &SetOrgAccessRunnerGroupRequest{ SelectedOrganizationIDs: []int64{1}, diff --git a/github/enterprise_billing_cost_centers_test.go b/github/enterprise_billing_cost_centers_test.go index ce047b862e7..5a188fd2d37 100644 --- a/github/enterprise_billing_cost_centers_test.go +++ b/github/enterprise_billing_cost_centers_test.go @@ -604,7 +604,7 @@ func TestCostCenters_Marshal(t *testing.T) { func TestCostCenterRequest_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &CostCenterRequest{}, "{}") + testJSONMarshal(t, &CostCenterRequest{}, `{"name": ""}`) u := &CostCenterRequest{ Name: "Engineering", diff --git a/github/enterprise_scim_test.go b/github/enterprise_scim_test.go index 2d6a45e85bf..f38d1a37384 100644 --- a/github/enterprise_scim_test.go +++ b/github/enterprise_scim_test.go @@ -117,9 +117,9 @@ func TestSCIMEnterpriseUsers_Marshal(t *testing.T) { want := `{ "schemas": ["` + SCIMSchemasURINamespacesListResponse + `"], - "TotalResults": 1, + "totalResults": 1, "itemsPerPage": 1, - "StartIndex": 1, + "startIndex": 1, "Resources": [{ "active": true, "emails": [{ @@ -161,55 +161,6 @@ func TestSCIMEnterpriseUsers_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } -func TestListProvisionedSCIMGroupsEnterpriseOptions_Marshal(t *testing.T) { - t.Parallel() - testJSONMarshal(t, &ListProvisionedSCIMGroupsEnterpriseOptions{}, "{}") - - u := &ListProvisionedSCIMGroupsEnterpriseOptions{ - Filter: Ptr("f"), - ExcludedAttributes: Ptr("ea"), - StartIndex: Ptr(5), - Count: Ptr(9), - } - - want := `{ - "filter": "f", - "excludedAttributes": "ea", - "startIndex": 5, - "count": 9 - }` - - testJSONMarshal(t, u, want) -} - -func TestGetProvisionedSCIMGroupEnterpriseOptions_Marshal(t *testing.T) { - t.Parallel() - testJSONMarshal(t, &GetProvisionedSCIMGroupEnterpriseOptions{}, "{}") - - u := &GetProvisionedSCIMGroupEnterpriseOptions{ExcludedAttributes: Ptr("ea")} - want := `{"excludedAttributes": "ea"}` - testJSONMarshal(t, u, want) -} - -func TestListProvisionedSCIMUsersEnterpriseOptions_Marshal(t *testing.T) { - t.Parallel() - testJSONMarshal(t, &ListProvisionedSCIMUsersEnterpriseOptions{}, "{}") - - u := &ListProvisionedSCIMUsersEnterpriseOptions{ - Filter: Ptr("f"), - StartIndex: Ptr(3), - Count: Ptr(7), - } - - want := `{ - "filter": "f", - "startIndex": 3, - "count": 7 - }` - - testJSONMarshal(t, u, want) -} - func TestSCIMEnterpriseGroupAttributes_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &SCIMEnterpriseGroupAttributes{}, "{}") @@ -255,7 +206,10 @@ func TestSCIMEnterpriseGroupAttributes_Marshal(t *testing.T) { func TestSCIMEnterpriseAttribute_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &SCIMEnterpriseAttribute{}, "{}") + testJSONMarshal(t, &SCIMEnterpriseAttribute{}, `{ + "schemas": null, + "Operations": null + }`) u := &SCIMEnterpriseAttribute{ Schemas: []string{"s"}, @@ -311,7 +265,8 @@ func TestSCIMEnterpriseAttribute_Marshal(t *testing.T) { ] }` - testJSONMarshal(t, u, want) + testJSONMarshalOnly(t, u, want) + // can't unmarshal Operations back into []*SCIMEnterpriseAttributeOperation, so skip testJSONUnmarshalOnly } func TestEnterpriseService_ListProvisionedSCIMGroups(t *testing.T) { diff --git a/github/event_test.go b/github/event_test.go index d26f4020771..e1f09e5c541 100644 --- a/github/event_test.go +++ b/github/event_test.go @@ -144,5 +144,5 @@ func TestEvent_Marshal(t *testing.T) { "id": "id" }` - testJSONMarshal(t, u, want) + testJSONMarshal(t, u, want, cmpJSONRawMessageComparator()) } diff --git a/github/event_types_test.go b/github/event_types_test.go index 2c0e7f88796..74ca820a033 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -6141,7 +6141,7 @@ func TestDeploymentEvent_Marshal(t *testing.T) { } }` - testJSONMarshal(t, u, want) + testJSONMarshal(t, u, want, cmpJSONRawMessageComparator()) } func TestDeploymentProtectionRuleEvent_Marshal(t *testing.T) { @@ -6529,7 +6529,7 @@ func TestDeploymentProtectionRuleEvent_Marshal(t *testing.T) { } }` - testJSONMarshal(t, u, want) + testJSONMarshal(t, u, want, cmpJSONRawMessageComparator()) } func TestDeploymentReviewEvent_Marshal(t *testing.T) { @@ -7466,7 +7466,7 @@ func TestDeploymentStatusEvent_Marshal(t *testing.T) { } }` - testJSONMarshal(t, u, want) + testJSONMarshal(t, u, want, cmpJSONRawMessageComparator()) } func TestDiscussionCommentEvent_Marshal(t *testing.T) { @@ -8576,7 +8576,6 @@ func TestPingEvent_Marshal(t *testing.T) { "key": "value" }, "config": { - "key": "value" }, "events": [ "a" @@ -9102,7 +9101,7 @@ func TestRepositoryDispatchEvent_Marshal(t *testing.T) { } }` - testJSONMarshal(t, u, want) + testJSONMarshal(t, u, want, cmpJSONRawMessageComparator()) } func TestRepositoryImportEvent_Marshal(t *testing.T) { @@ -12129,7 +12128,7 @@ func TestWorkflowDispatchEvent_Marshal(t *testing.T) { } }` - testJSONMarshal(t, u, want) + testJSONMarshal(t, u, want, cmpJSONRawMessageComparator()) } func TestWatchEvent_Marshal(t *testing.T) { @@ -13465,7 +13464,7 @@ func TestMetaEvent_Marshal(t *testing.T) { func TestRequestedAction_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &RequestedAction{}, "{}") + testJSONMarshal(t, &RequestedAction{}, `{"identifier": ""}`) r := &RequestedAction{ Identifier: "i", @@ -13857,11 +13856,6 @@ func TestCustomPropertyEvent_Marshal(t *testing.T) { ], "values_editable_by": "org_actors" }, - "repository": { - "id": 1, - "name": "n", - "url": "s" - }, "sender": { "login": "l", "id": 1, @@ -16414,7 +16408,7 @@ func TestPullRequestEvent_Marshal(t *testing.T) { } }` - testJSONMarshal(t, u, want) + testJSONMarshal(t, u, want, cmpJSONRawMessageComparator()) } func TestPullRequestReviewCommentEvent_Marshal(t *testing.T) { @@ -18037,7 +18031,6 @@ func TestSecurityAdvisoryEvent_Marshal(t *testing.T) { ], "published_at": ` + referenceTimeStr + `, "updated_at": ` + referenceTimeStr + `, - "withdrawn_at": null, "vulnerabilities": [ { "package": { @@ -18534,8 +18527,7 @@ func TestSecurityAndAnalysisEvent_Marshal(t *testing.T) { "url": "u", "events_url": "e", "repos_url": "r" - }, - "target_type": "running" + } }` testJSONMarshal(t, u, want) @@ -18727,10 +18719,6 @@ func TestCodeScanningAlertEvent_Marshal(t *testing.T) { } ], "state": "open", - "fixed_at": null, - "dismissed_by": null, - "dismissed_at": null, - "dismissed_reason": null, "rule": { "id": "Style/FrozenStringLiteralComment", "severity": "note", @@ -18742,8 +18730,7 @@ func TestCodeScanningAlertEvent_Marshal(t *testing.T) { "help": "help" }, "tool": { - "name": "Rubocop", - "version": null + "name": "Rubocop" } }, "ref": "refs/heads/main", @@ -18775,7 +18762,6 @@ func TestCodeScanningAlertEvent_Marshal(t *testing.T) { "site_admin": false }, "html_url": "a", - "description": null, "fork": false, "url": "a", "forks_url": "a", @@ -18821,23 +18807,18 @@ func TestCodeScanningAlertEvent_Marshal(t *testing.T) { "ssh_url": "a", "clone_url": "a", "svn_url": "a", - "homepage": null, "size": 0, "stargazers_count": 0, "watchers_count": 0, - "language": null, "has_issues": true, "has_projects": true, "has_downloads": true, "has_wiki": true, "has_pages": true, "forks_count": 0, - "mirror_url": null, "archived": false, "disabled": false, "open_issues_count": 2, - "license": null, - "forks": 0, "open_issues": 2, "watchers": 0, "default_branch": "main" diff --git a/github/git_refs_test.go b/github/git_refs_test.go index 4c2e72fbc89..76ed3e2f5bd 100644 --- a/github/git_refs_test.go +++ b/github/git_refs_test.go @@ -635,7 +635,11 @@ func TestGitService_UpdateRef_pathEscape(t *testing.T) { func TestReference_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &Reference{}, "{}") + testJSONMarshal(t, &Reference{}, `{ + "ref": null, + "url": null, + "object": null + }`) u := &Reference{ Ref: Ptr("ref"), @@ -664,7 +668,11 @@ func TestReference_Marshal(t *testing.T) { func TestGitObject_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &GitObject{}, "{}") + testJSONMarshal(t, &GitObject{}, `{ + "type": null, + "sha": null, + "url": null + }`) u := &GitObject{ Type: Ptr("type"), diff --git a/github/git_trees_test.go b/github/git_trees_test.go index 54015739f24..037a30895cd 100644 --- a/github/git_trees_test.go +++ b/github/git_trees_test.go @@ -382,7 +382,7 @@ func TestTree_Marshal(t *testing.T) { func TestTreeEntry_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &TreeEntry{}, "{}") + testJSONMarshal(t, &TreeEntry{}, `{"sha": null}`) u := &TreeEntry{ SHA: Ptr("sha"), @@ -409,7 +409,7 @@ func TestTreeEntry_Marshal(t *testing.T) { func TestTreeEntryWithFileDelete_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &treeEntryWithFileDelete{}, "{}") + testJSONMarshal(t, &treeEntryWithFileDelete{}, `{"sha": null}`) u := &treeEntryWithFileDelete{ SHA: Ptr("sha"), @@ -436,7 +436,7 @@ func TestTreeEntryWithFileDelete_Marshal(t *testing.T) { func TestCreateTree_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &createTree{}, "{}") + testJSONMarshal(t, &createTree{}, `{"tree": null}`) u := &createTree{ BaseTree: "bt", diff --git a/github/github_test.go b/github/github_test.go index 0f415f416eb..da6d1302f06 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -161,32 +161,114 @@ func testBody(t *testing.T, r *http.Request, want string) { } } -// Test whether the marshaling of v produces JSON that corresponds -// to the want string. -func testJSONMarshal(t *testing.T, v any, want string) { +// testJSONMarshal tests both JSON marshaling and unmarshaling of a value by comparing +// the marshaled output with the expected JSON string. +// +// This is the recommended function for most use cases. +// It performs a round-trip test that ensures both marshaling (Go value to JSON) +// and unmarshaling (JSON to Go value) work correctly and produce semantically equivalent results. +func testJSONMarshal[T any](t *testing.T, v T, want string, opts ...cmp.Option) { t.Helper() - // Unmarshal the wanted JSON, to verify its correctness, and marshal it back - // to sort the keys. - u := reflect.New(reflect.TypeOf(v)).Interface() - if err := json.Unmarshal([]byte(want), &u); err != nil { - t.Errorf("Unable to unmarshal JSON for %v: %v", want, err) - } - w, err := json.MarshalIndent(u, "", " ") + + testJSONMarshalOnly(t, v, want) + testJSONUnmarshalOnly(t, v, want, opts...) +} + +// testJSONMarshalOnly tests JSON marshaling by comparing the marshaled output with the expected JSON string. +// +// This function compares JSON by unmarshaling both values into any and using cmp.Diff. +// This means the comparison ignores: +// - White space differences +// - Key ordering in objects +// - Numeric type differences (e.g., int vs float with same value) +// +// In most cases, use testJSONMarshal instead. +// Only use this function in rare cases where you need to test marshaling behavior in isolation. +func testJSONMarshalOnly[T any](t *testing.T, v T, want string) { + t.Helper() + + got, err := json.Marshal(v) if err != nil { - t.Errorf("Unable to marshal JSON for %#v", u) + t.Fatalf("Unable to marshal got JSON for %#v: %v", v, err) } - // Marshal the target value. - got, err := json.MarshalIndent(v, "", " ") - if err != nil { - t.Errorf("Unable to marshal JSON for %#v", v) + // Unmarshal both the marshaled output and expected JSON into any + // to enable semantic comparison that ignores formatting differences + var gotAny any + if err := json.Unmarshal(got, &gotAny); err != nil { + t.Fatalf("Unable to unmarshal got JSON %v: %v", got, err) + } + + var wantAny any + if err := json.Unmarshal([]byte(want), &wantAny); err != nil { + t.Fatalf("Unable to unmarshal want JSON %v: %v", want, err) + } + + // Compare the semantic content + if diff := cmp.Diff(wantAny, gotAny); diff != "" { + t.Errorf("json.Marshal returned:\n%v\nwant:\n%v\ndiff:\n%v", got, want, diff) + } +} + +// testJSONUnmarshalOnly tests JSON unmarshaling by parsing the JSON string +// and comparing the result with the expected value. +// +// In most cases, use testJSONMarshal instead. +// Only use this function in rare cases where you need to test unmarshaling behavior in isolation. +func testJSONUnmarshalOnly[T any](t *testing.T, want T, v string, opts ...cmp.Option) { + t.Helper() + + var got T + if err := json.Unmarshal([]byte(v), &got); err != nil { + t.Fatalf("Unable to unmarshal JSON %v: %v", v, err) } - if diff := cmp.Diff(string(w), string(got)); diff != "" { - t.Errorf("json.Marshal returned:\n%v\nwant:\n%v\ndiff:\n%v", got, w, diff) + if diff := cmp.Diff(want, got, opts...); diff != "" { + t.Errorf("json.Unmarshal returned:\n%#v\nwant:\n%#v\ndiff:\n%v", got, want, diff) } } +// cmpJSONRawMessageComparator returns an option for use in testJSONUnmarshalData that compares +// json.RawMessage values by their semantic JSON content rather than byte-for-byte equality. +func cmpJSONRawMessageComparator() cmp.Option { + return cmp.Comparer(func(x, y json.RawMessage) bool { + if len(x) == 0 && len(y) == 0 { + return true + } + var xVal, yVal any + if err := json.Unmarshal(x, &xVal); err != nil { + return false + } + if err := json.Unmarshal(y, &yVal); err != nil { + return false + } + return cmp.Equal(xVal, yVal) + }) +} + +// cmpIgnoreFieldOption returns an option for use in testJSONUnmarshalData that ignores a specific +// field by name, but only when it's a top-level field (not nested within other structs). +// This prevents accidentally ignoring nested struct fields with the same name. +func cmpIgnoreFieldOption(fieldName string) cmp.Option { + return cmp.FilterPath(func(p cmp.Path) bool { + if len(p) == 0 { + return false + } + sf, ok := p[len(p)-1].(cmp.StructField) + if !ok || sf.Name() != fieldName { + return false + } + // Only ignore top-level fields (path contains exactly one StructField) + structFieldCount := 0 + for i := range p { + if _, ok := p[i].(cmp.StructField); ok { + structFieldCount++ + } + } + return structFieldCount == 1 + }, cmp.Ignore()) +} + // Test how bad options are handled. Method f under test should // return an error. func testBadOptions(t *testing.T, methodName string, f func() error) { @@ -3061,7 +3143,10 @@ func TestBareDo_returnsOpenBody(t *testing.T) { func TestErrorResponse_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &ErrorResponse{}, "{}") + testJSONMarshal(t, &ErrorResponse{}, `{ + "message": "", + "errors": null + }`) u := &ErrorResponse{ Message: "msg", @@ -3119,7 +3204,16 @@ func TestErrorBlock_Marshal(t *testing.T) { func TestRateLimitError_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &RateLimitError{}, "{}") + testJSONMarshal(t, &RateLimitError{}, `{ + "Rate": { + "limit": 0, + "remaining": 0, + "reset": `+emptyTimeStr+`, + "used": 0 + }, + "Response": null, + "message": "" + }`) u := &RateLimitError{ Rate: Rate{ @@ -3134,8 +3228,10 @@ func TestRateLimitError_Marshal(t *testing.T) { "Rate": { "limit": 1, "remaining": 1, - "reset": ` + referenceTimeStr + ` + "reset": ` + referenceTimeStr + `, + "used": 0 }, + "Response": null, "message": "msg" }` @@ -3144,14 +3240,20 @@ func TestRateLimitError_Marshal(t *testing.T) { func TestAbuseRateLimitError_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &AbuseRateLimitError{}, "{}") + testJSONMarshal(t, &AbuseRateLimitError{}, `{ + "Response": null, + "message": "", + "RetryAfter": null + }`) u := &AbuseRateLimitError{ Message: "msg", } want := `{ - "message": "msg" + "Response": null, + "message": "msg", + "RetryAfter": null }` testJSONMarshal(t, u, want) @@ -3159,7 +3261,12 @@ func TestAbuseRateLimitError_Marshal(t *testing.T) { func TestError_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &Error{}, "{}") + testJSONMarshal(t, &Error{}, `{ + "resource": "", + "field": "", + "code": "", + "message": "" + }`) u := &Error{ Resource: "res", diff --git a/github/issue_import_test.go b/github/issue_import_test.go index 3968a470654..d26d2013dd5 100644 --- a/github/issue_import_test.go +++ b/github/issue_import_test.go @@ -369,7 +369,7 @@ func TestIssueImportResponse_Marshal(t *testing.T) { func TestComment_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &Comment{}, "{}") + testJSONMarshal(t, &Comment{}, `{"body": ""}`) u := &Comment{ CreatedAt: &Timestamp{referenceTime}, @@ -386,7 +386,10 @@ func TestComment_Marshal(t *testing.T) { func TestIssueImport_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &IssueImport{}, "{}") + testJSONMarshal(t, &IssueImport{}, `{ + "title": "", + "body": "" + }`) u := &IssueImport{ Title: "title", @@ -419,7 +422,12 @@ func TestIssueImport_Marshal(t *testing.T) { func TestIssueImportRequest_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &IssueImportRequest{}, "{}") + testJSONMarshal(t, &IssueImportRequest{}, `{ + "issue": { + "title": "", + "body": "" + } + }`) u := &IssueImportRequest{ IssueImport: IssueImport{ diff --git a/github/issues_events_test.go b/github/issues_events_test.go index ac65013f2e5..c9778161752 100644 --- a/github/issues_events_test.go +++ b/github/issues_events_test.go @@ -429,9 +429,6 @@ func TestIssueEvent_Marshal(t *testing.T) { "to": "to" }, "lock_reason": "lr", - "project_card": { - "id": 1 - }, "dismissed_review": { "state": "state", "review_id": 1, diff --git a/github/issues_timeline_test.go b/github/issues_timeline_test.go index de8ee202512..c2c2058fcd4 100644 --- a/github/issues_timeline_test.go +++ b/github/issues_timeline_test.go @@ -246,9 +246,6 @@ func TestTimeline_Marshal(t *testing.T) { "from": "from", "to": "to" }, - "project_card": { - "id": 1 - }, "state": "state" }` diff --git a/github/meta_test.go b/github/meta_test.go index 062cb84274a..772ec96aa6a 100644 --- a/github/meta_test.go +++ b/github/meta_test.go @@ -34,18 +34,14 @@ func TestAPIMeta_Marshal(t *testing.T) { Domains: &APIMetaDomains{ Website: []string{ "*.github.com", - "*.github.dev", - "*.github.io", "*.example.com/assets", "*.example.com", }, ArtifactAttestations: &APIMetaArtifactAttestations{ TrustDomain: "", Services: []string{ - "*.actions.github.com", - "tuf-repo.github.com", - "fulcio.github.com", - "timestamp.github.com", + "*.actions.example.com", + "timestamp.example.com", }, }, }, @@ -58,13 +54,13 @@ func TestAPIMeta_Marshal(t *testing.T) { "importer":["i"], "github_enterprise_importer":["gei"], "actions":["a"], - "actions_macos":["example.com/1", "example.com/2"], + "actions_macos":["example.com/1", "example.com/2"], "dependabot":["d"], "ssh_key_fingerprints":{"a":"f"}, "ssh_keys":["k"], "api":["a"], "web":["w"], - "domains":{"website":["*.github.com","*.github.dev","*.github.io","*.example.com/assets","*.example.com"],"artifact_attestations":{"trust_domain":"","services":["*.actions.github.com","tuf-repo.github.com","fulcio.github.com","timestamp.github.com"]}} + "domains":{"website":["*.github.com","*.example.com/assets","*.example.com"],"artifact_attestations":{"services":["*.actions.example.com","timestamp.example.com"]}} }` testJSONMarshal(t, a, want) diff --git a/github/orgs_audit_log_test.go b/github/orgs_audit_log_test.go index a9235cfb288..b6b518d15e1 100644 --- a/github/orgs_audit_log_test.go +++ b/github/orgs_audit_log_test.go @@ -172,35 +172,6 @@ func TestOrganizationService_GetAuditLog(t *testing.T) { }) } -func TestGetAuditLogOptions_Marshal(t *testing.T) { - t.Parallel() - testJSONMarshal(t, &GetAuditLogOptions{}, "{}") - - u := &GetAuditLogOptions{ - Phrase: Ptr("p"), - Include: Ptr("i"), - Order: Ptr("o"), - ListCursorOptions: ListCursorOptions{ - Page: "p", - PerPage: 1, - After: "a", - Before: "b", - }, - } - - want := `{ - "phrase": "p", - "include": "i", - "order": "o", - "Page": "p", - "PerPage": 1, - "After": "a", - "Before": "b" - }` - - testJSONMarshal(t, u, want) -} - func TestHookConfig_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &HookConfig{}, "{}") @@ -418,5 +389,6 @@ func TestAuditEntry_Marshal(t *testing.T) { } }` - testJSONMarshal(t, u, want) + testJSONMarshalOnly(t, u, want) + // can't unmarshal AdditionalFields back into map[string]any, so skip testJSONUnmarshalOnly } diff --git a/github/orgs_personal_access_tokens_test.go b/github/orgs_personal_access_tokens_test.go index 760e83c2457..568b8706ca3 100644 --- a/github/orgs_personal_access_tokens_test.go +++ b/github/orgs_personal_access_tokens_test.go @@ -421,7 +421,7 @@ func TestOrganizationsService_ReviewPersonalAccessTokenRequest(t *testing.T) { func TestReviewPersonalAccessTokenRequestOptions_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &ReviewPersonalAccessTokenRequestOptions{}, "{}") + testJSONMarshal(t, &ReviewPersonalAccessTokenRequestOptions{}, `{"action": ""}`) u := &ReviewPersonalAccessTokenRequestOptions{ Action: "a", diff --git a/github/packages_test.go b/github/packages_test.go index ba453b55750..3bac6a6c014 100644 --- a/github/packages_test.go +++ b/github/packages_test.go @@ -442,7 +442,7 @@ func TestPackageVersion_Marshal(t *testing.T) { "deleted_at": ` + referenceTimeStr + ` }` - testJSONMarshal(t, o, want) + testJSONMarshal(t, o, want, cmpJSONRawMessageComparator()) } func TestPackageVersion_GetBody(t *testing.T) { @@ -1054,14 +1054,14 @@ func TestPackageVersionBodyInfo_Marshal(t *testing.T) { func TestPackageEventContainerMetadata_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &PackageContainerMetadata{}, "{}") + testJSONMarshal(t, &PackageEventContainerMetadata{}, "{}") o := &PackageEventContainerMetadata{ Labels: map[string]any{ "k": "v", }, Manifest: map[string]any{ - "k": 1, + "k": float64(1), }, Tag: &PackageEventContainerMetadataTag{ Name: Ptr("n"), @@ -1163,7 +1163,7 @@ func TestPackageNugetMetadata_Marshal(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { t.Parallel() - testJSONMarshal(t, test.input, test.want) + testJSONMarshal(t, test.input, test.want, cmpJSONRawMessageComparator()) }) } } @@ -1209,7 +1209,7 @@ func TestPackageNPMMetadata_Marshal(t *testing.T) { Repository: map[string]string{"k1": "v1"}, Engines: map[string]string{"k1": "v1"}, Directories: map[string]string{"k1": "v1"}, - Scripts: map[string]any{"k1": 1}, + Scripts: map[string]any{"k1": float64(1)}, Bin: map[string]any{"k1": true}, Man: map[string]any{"k1": "v1"}, Keywords: []string{"kw1", "kw2"}, @@ -1228,7 +1228,7 @@ func TestPackageNPMMetadata_Marshal(t *testing.T) { "homepage": "h", "license": "l", "main": "m", - "ID": "id", + "id": "id", "node_version": "nv", "npm_version": "npmv", "readme": "r", diff --git a/github/rate_limit_test.go b/github/rate_limit_test.go index 38c313fe38a..d8a45d93a85 100644 --- a/github/rate_limit_test.go +++ b/github/rate_limit_test.go @@ -388,7 +388,20 @@ func TestRateLimits_overQuota(t *testing.T) { func TestRateLimits_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &RateLimits{}, "{}") + testJSONMarshal(t, &RateLimits{}, `{ + "core": null, + "search": null, + "graphql": null, + "integration_manifest": null, + "source_import": null, + "code_scanning_upload": null, + "actions_runner_registration": null, + "scim": null, + "dependency_snapshots": null, + "code_search": null, + "audit_log": null, + "dependency_sbom": null + }`) u := &RateLimits{ Core: &Rate{ @@ -545,7 +558,12 @@ func TestRateLimits_Marshal(t *testing.T) { func TestRate_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &Rate{}, "{}") + testJSONMarshal(t, &Rate{}, `{ + "limit": 0, + "remaining": 0, + "used": 0, + "reset": "0001-01-01T00:00:00Z" + }`) u := &Rate{ Limit: 1, diff --git a/github/repos_codeowners_test.go b/github/repos_codeowners_test.go index a7f0d2924e7..1da3c1ee9d5 100644 --- a/github/repos_codeowners_test.go +++ b/github/repos_codeowners_test.go @@ -139,7 +139,7 @@ func TestRepositoriesService_GetCodeownersErrors_specificRef(t *testing.T) { func TestCodeownersErrors_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &CodeownersErrors{}, "{}") + testJSONMarshal(t, &CodeownersErrors{}, `{"errors": null}`) u := &CodeownersErrors{ Errors: []*CodeownersError{ diff --git a/github/repos_comments_test.go b/github/repos_comments_test.go index 2fa08ff1f08..09e531c5c71 100644 --- a/github/repos_comments_test.go +++ b/github/repos_comments_test.go @@ -295,7 +295,7 @@ func TestRepositoriesService_DeleteComment_invalidOwner(t *testing.T) { func TestRepositoryComment_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &RepositoryComment{}, "{}") + testJSONMarshal(t, &RepositoryComment{}, `{"body": null}`) r := &RepositoryComment{ HTMLURL: Ptr("hurl"), diff --git a/github/repos_community_health_test.go b/github/repos_community_health_test.go index 43d60ff4636..949a695a6b2 100644 --- a/github/repos_community_health_test.go +++ b/github/repos_community_health_test.go @@ -134,7 +134,14 @@ func TestRepositoriesService_GetCommunityHealthMetrics(t *testing.T) { func TestMetric_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &Metric{}, "{}") + testJSONMarshal(t, &Metric{}, `{ + "name": null, + "key": null, + "spdx_id": null, + "url": null, + "html_url": null, + "node_id": null + }`) r := &Metric{ Name: Ptr("name"), @@ -159,7 +166,15 @@ func TestMetric_Marshal(t *testing.T) { func TestCommunityHealthFiles_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &CommunityHealthFiles{}, "{}") + testJSONMarshal(t, &CommunityHealthFiles{}, `{ + "code_of_conduct": null, + "code_of_conduct_file": null, + "contributing": null, + "issue_template": null, + "pull_request_template": null, + "license": null, + "readme": null + }`) r := &CommunityHealthFiles{ CodeOfConduct: &Metric{ @@ -213,31 +228,41 @@ func TestCommunityHealthFiles_Marshal(t *testing.T) { "name": "name", "key": "key", "url": "url", - "html_url": "hurl" + "html_url": "hurl", + "node_id": null, + "spdx_id": null }, "code_of_conduct_file": { "name": "name", "key": "key", - "url": "url", - "html_url": "hurl" - }, + "url": "url", + "html_url": "hurl", + "node_id": null, + "spdx_id": null + }, "contributing": { "name": "name", "key": "key", "url": "url", - "html_url": "hurl" + "html_url": "hurl", + "node_id": null, + "spdx_id": null }, "issue_template": { "name": "name", "key": "key", "url": "url", - "html_url": "hurl" + "html_url": "hurl", + "node_id": null, + "spdx_id": null }, "pull_request_template": { "name": "name", "key": "key", "url": "url", - "html_url": "hurl" + "html_url": "hurl", + "node_id": null, + "spdx_id": null }, "license": { "name": "name", @@ -251,7 +276,9 @@ func TestCommunityHealthFiles_Marshal(t *testing.T) { "name": "name", "key": "key", "url": "url", - "html_url": "hurl" + "html_url": "hurl", + "node_id": null, + "spdx_id": null } }` @@ -260,7 +287,14 @@ func TestCommunityHealthFiles_Marshal(t *testing.T) { func TestCommunityHealthMetrics_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &CommunityHealthMetrics{}, "{}") + testJSONMarshal(t, &CommunityHealthMetrics{}, `{ + "health_percentage": null, + "description": null, + "documentation": null, + "files": null, + "updated_at": null, + "content_reports_enabled": null + }`) r := &CommunityHealthMetrics{ HealthPercentage: Ptr(1), @@ -325,31 +359,41 @@ func TestCommunityHealthMetrics_Marshal(t *testing.T) { "name": "name", "key": "key", "url": "url", - "html_url": "hurl" + "html_url": "hurl", + "node_id": null, + "spdx_id": null }, "code_of_conduct_file": { - "name": "name", - "key": "key", - "url": "url", - "html_url": "hurl" - }, + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl", + "node_id": null, + "spdx_id": null + }, "contributing": { "name": "name", "key": "key", "url": "url", - "html_url": "hurl" + "html_url": "hurl", + "node_id": null, + "spdx_id": null }, "issue_template": { "name": "name", "key": "key", "url": "url", - "html_url": "hurl" + "html_url": "hurl", + "node_id": null, + "spdx_id": null }, "pull_request_template": { "name": "name", "key": "key", "url": "url", - "html_url": "hurl" + "html_url": "hurl", + "node_id": null, + "spdx_id": null }, "license": { "name": "name", @@ -363,7 +407,9 @@ func TestCommunityHealthMetrics_Marshal(t *testing.T) { "name": "name", "key": "key", "url": "url", - "html_url": "hurl" + "html_url": "hurl", + "node_id": null, + "spdx_id": null } }, "updated_at": ` + referenceTimeStr + `, diff --git a/github/repos_contents_test.go b/github/repos_contents_test.go index ed782da8701..d241f7a49f8 100644 --- a/github/repos_contents_test.go +++ b/github/repos_contents_test.go @@ -1066,7 +1066,7 @@ func TestRepositoryContent_Marshal(t *testing.T) { func TestRepositoryContentResponse_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &RepositoryContentResponse{}, "{}") + testJSONMarshal(t, &RepositoryContentResponse{}, `{"commit": {}}`) r := &RepositoryContentResponse{ Content: &RepositoryContent{ @@ -1190,7 +1190,7 @@ func TestRepositoryContentResponse_Marshal(t *testing.T) { func TestRepositoryContentFileOptions_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &RepositoryContentFileOptions{}, "{}") + testJSONMarshal(t, &RepositoryContentFileOptions{}, `{"content": null}`) r := &RepositoryContentFileOptions{ Message: Ptr("type"), diff --git a/github/repos_hooks_deliveries_test.go b/github/repos_hooks_deliveries_test.go index 92782f2b5ee..eb5043ae479 100644 --- a/github/repos_hooks_deliveries_test.go +++ b/github/repos_hooks_deliveries_test.go @@ -290,7 +290,7 @@ func TestHookRequest_Marshal(t *testing.T) { } }` - testJSONMarshal(t, r, want) + testJSONMarshal(t, r, want, cmpJSONRawMessageComparator()) } func TestHookRequest_GetHeader(t *testing.T) { @@ -351,7 +351,7 @@ func TestHookResponse_Marshal(t *testing.T) { } }` - testJSONMarshal(t, r, want) + testJSONMarshal(t, r, want, cmpJSONRawMessageComparator()) } func TestHookResponse_GetHeader(t *testing.T) { @@ -450,5 +450,5 @@ func TestHookDelivery_Marshal(t *testing.T) { } }` - testJSONMarshal(t, r, want) + testJSONMarshal(t, r, want, cmpJSONRawMessageComparator()) } diff --git a/github/repos_hooks_test.go b/github/repos_hooks_test.go index b391acc4ea2..ca8603a8889 100644 --- a/github/repos_hooks_test.go +++ b/github/repos_hooks_test.go @@ -505,7 +505,7 @@ func TestBranchWebHookCommit_Marshal(t *testing.T) { func TestBranchCreateHookRequest_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &createHookRequest{}, "{}") + testJSONMarshal(t, &createHookRequest{}, `{"name": ""}`) v := &createHookRequest{ Name: "abc", diff --git a/github/repos_pages_test.go b/github/repos_pages_test.go index 5936999739c..d0942fdd6cd 100644 --- a/github/repos_pages_test.go +++ b/github/repos_pages_test.go @@ -572,7 +572,7 @@ func TestPagesError_Marshal(t *testing.T) { func TestPagesUpdate_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &PagesUpdate{}, "{}") + testJSONMarshal(t, &PagesUpdate{}, `{"cname": null}`) u := &PagesUpdate{ CNAME: Ptr("cname"), diff --git a/github/repos_releases_test.go b/github/repos_releases_test.go index ba73826c8b1..d81ecb7383e 100644 --- a/github/repos_releases_test.go +++ b/github/repos_releases_test.go @@ -921,7 +921,7 @@ func TestRepositoryRelease_Marshal(t *testing.T) { func TestGenerateNotesOptions_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &GenerateNotesOptions{}, "{}") + testJSONMarshal(t, &GenerateNotesOptions{}, `{"tag_name": ""}`) u := &GenerateNotesOptions{ TagName: "tag_name", diff --git a/github/repos_tags_test.go b/github/repos_tags_test.go index 0a198859cde..ea1e9a2bb7f 100644 --- a/github/repos_tags_test.go +++ b/github/repos_tags_test.go @@ -132,7 +132,10 @@ func TestRepositoriesService_DeleteTagProtection(t *testing.T) { func TestTagProtection_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &TagProtection{}, "{}") + testJSONMarshal(t, &TagProtection{}, `{ + "id": null, + "pattern": null + }`) u := &TagProtection{ ID: Ptr(int64(1)), diff --git a/github/repos_test.go b/github/repos_test.go index c943c12947d..722317a64be 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -4341,7 +4341,7 @@ func TestAuthorizedActorsOnly_Marshal(t *testing.T) { func TestDispatchRequestOptions_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &DispatchRequestOptions{}, "{}") + testJSONMarshal(t, &DispatchRequestOptions{}, `{"event_type": ""}`) cp := json.RawMessage(`{"testKey":"testValue"}`) u := &DispatchRequestOptions{ @@ -4356,12 +4356,12 @@ func TestDispatchRequestOptions_Marshal(t *testing.T) { } }` - testJSONMarshal(t, u, want) + testJSONMarshal(t, u, want, cmpJSONRawMessageComparator()) } func TestTransferRequest_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &TransferRequest{}, "{}") + testJSONMarshal(t, &TransferRequest{}, `{"new_owner": ""}`) u := &TransferRequest{ NewOwner: "testOwner", @@ -4428,7 +4428,7 @@ func TestDismissalRestrictionsRequest_Marshal(t *testing.T) { func TestAdminEnforcement_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &AdminEnforcement{}, "{}") + testJSONMarshal(t, &AdminEnforcement{}, `{"enabled": false}`) u := &AdminEnforcement{ URL: Ptr("https://www.example.com"), @@ -4445,7 +4445,7 @@ func TestAdminEnforcement_Marshal(t *testing.T) { func TestPullRequestReviewsEnforcementUpdate_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &PullRequestReviewsEnforcementUpdate{}, "{}") + testJSONMarshal(t, &PullRequestReviewsEnforcementUpdate{}, `{"required_approving_review_count": 0}`) u := &PullRequestReviewsEnforcementUpdate{ BypassPullRequestAllowancesRequest: &BypassPullRequestAllowancesRequest{ @@ -4474,7 +4474,7 @@ func TestPullRequestReviewsEnforcementUpdate_Marshal(t *testing.T) { func TestRequiredStatusCheck_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &RequiredStatusCheck{}, "{}") + testJSONMarshal(t, &RequiredStatusCheck{}, `{"context": ""}`) u := &RequiredStatusCheck{ Context: "ctx", diff --git a/github/repos_traffic_test.go b/github/repos_traffic_test.go index 0d80d513032..51416f13b71 100644 --- a/github/repos_traffic_test.go +++ b/github/repos_traffic_test.go @@ -235,7 +235,7 @@ func TestTrafficViews_Marshal(t *testing.T) { want := `{ "views": [{ - "timestamp": "2016-05-31T16:00:00.000Z", + "timestamp": "2016-05-31T16:00:00Z", "count": 7, "uniques": 6 }], @@ -262,7 +262,7 @@ func TestTrafficClones_Marshal(t *testing.T) { want := `{ "clones": [{ - "timestamp": "2021-10-29T16:00:00.000Z", + "timestamp": "2021-10-29T16:00:00Z", "count": 1, "uniques": 1 }], @@ -305,25 +305,10 @@ func TestTrafficData_Marshal(t *testing.T) { } want := `{ - "timestamp": "2016-05-31T16:00:00.000Z", + "timestamp": "2016-05-31T16:00:00Z", "count": 7, "uniques": 6 }` testJSONMarshal(t, u, want) } - -func TestTrafficBreakdownOptions_Marshal(t *testing.T) { - t.Parallel() - testJSONMarshal(t, &TrafficBreakdownOptions{}, "{}") - - u := &TrafficBreakdownOptions{ - Per: "day", - } - - want := `{ - "per": "day" - }` - - testJSONMarshal(t, u, want) -} diff --git a/github/scim_test.go b/github/scim_test.go index 985fcb5f2f2..be5fd367f5d 100644 --- a/github/scim_test.go +++ b/github/scim_test.go @@ -411,7 +411,7 @@ func TestSCIMUserAttributes_Marshal(t *testing.T) { func TestUpdateAttributeForSCIMUserOperations_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &UpdateAttributeForSCIMUserOperations{}, `{}`) + testJSONMarshal(t, &UpdateAttributeForSCIMUserOperations{}, `{"op": ""}`) u := &UpdateAttributeForSCIMUserOperations{ Op: "TestOp", @@ -428,7 +428,11 @@ func TestUpdateAttributeForSCIMUserOperations_Marshal(t *testing.T) { func TestUpdateAttributeForSCIMUserOptions_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &UpdateAttributeForSCIMUserOptions{}, `{}`) + testJSONMarshal(t, &UpdateAttributeForSCIMUserOptions{}, `{ + "operations": { + "op": "" + } + }`) u := &UpdateAttributeForSCIMUserOptions{ Schemas: []string{"test", "schema"}, diff --git a/github/search_test.go b/github/search_test.go index 645711715e6..fc30fc75ebe 100644 --- a/github/search_test.go +++ b/github/search_test.go @@ -845,30 +845,6 @@ func TestLabelResult_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } -func TestSearchOptions_Marshal(t *testing.T) { - t.Parallel() - testJSONMarshal(t, &SearchOptions{}, "{}") - - u := &SearchOptions{ - Sort: "author-date", - Order: "asc", - TextMatch: false, - ListOptions: ListOptions{ - Page: int(1), - PerPage: int(10), - }, - } - - want := `{ - "sort": "author-date", - "order": "asc", - "page": 1, - "perPage": 10 - }` - - testJSONMarshal(t, u, want) -} - func TestIssuesSearchResult_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &IssuesSearchResult{}, "{}") @@ -1031,7 +1007,6 @@ func TestCommitResult_Marshal(t *testing.T) { Commit: &Commit{SHA: Ptr("test")}, Author: &User{ID: Ptr(int64(1))}, Committer: &User{ID: Ptr(int64(1))}, - Parents: []*Commit{}, } want := `{ diff --git a/github/secret_scanning_pattern_configs_test.go b/github/secret_scanning_pattern_configs_test.go index 11ae9765b56..8ef43a720a5 100644 --- a/github/secret_scanning_pattern_configs_test.go +++ b/github/secret_scanning_pattern_configs_test.go @@ -532,7 +532,10 @@ func TestSecretScanningPatternConfigsUpdateOptions_Marshal(t *testing.T) { func TestSecretScanningProviderPatternSetting_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &SecretScanningProviderPatternSetting{}, `{}`) + testJSONMarshal(t, &SecretScanningProviderPatternSetting{}, `{ + "token_type": "", + "push_protection_setting": "" + }`) v := SecretScanningProviderPatternSetting{ TokenType: "GITHUB_PERSONAL_ACCESS_TOKEN", @@ -549,7 +552,10 @@ func TestSecretScanningProviderPatternSetting_Marshal(t *testing.T) { func TestSecretScanningCustomPatternSetting_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &SecretScanningCustomPatternSetting{}, `{}`) + testJSONMarshal(t, &SecretScanningCustomPatternSetting{}, `{ + "token_type": "", + "push_protection_setting": "" + }`) v := SecretScanningCustomPatternSetting{ TokenType: "cp_2", diff --git a/github/secret_scanning_test.go b/github/secret_scanning_test.go index 7ddcda9de50..97ee161f001 100644 --- a/github/secret_scanning_test.go +++ b/github/secret_scanning_test.go @@ -602,7 +602,7 @@ func TestSecretScanningAlertLocationDetails_Marshal(t *testing.T) { func TestSecretScanningAlertUpdateOptions_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &SecretScanningAlertUpdateOptions{}, `{}`) + testJSONMarshal(t, &SecretScanningAlertUpdateOptions{}, `{"state": ""}`) u := &SecretScanningAlertUpdateOptions{ State: "open", diff --git a/github/teams_members_test.go b/github/teams_members_test.go index 38e2d54e054..b549dd2b6b4 100644 --- a/github/teams_members_test.go +++ b/github/teams_members_test.go @@ -803,24 +803,3 @@ func TestTeamAddTeamMembershipOptions_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } - -func TestTeamListTeamMembersOptions_Marshal(t *testing.T) { - t.Parallel() - testJSONMarshal(t, &TeamListTeamMembersOptions{}, "{}") - - u := &TeamListTeamMembersOptions{ - Role: "role", - ListOptions: ListOptions{ - Page: 1, - PerPage: 2, - }, - } - - want := `{ - "role": "role", - "Page": 1, - "PerPage": 2 - }` - - testJSONMarshal(t, u, want) -} diff --git a/github/teams_test.go b/github/teams_test.go index c1de4fea406..2efc1cd4f9a 100644 --- a/github/teams_test.go +++ b/github/teams_test.go @@ -1579,7 +1579,7 @@ func TestTeamsService_CreateOrUpdateIDPGroupConnectionsBySlug_empty(t *testing.T func TestNewTeam_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &NewTeam{}, "{}") + testJSONMarshal(t, &NewTeam{}, `{"name": ""}`) u := &NewTeam{ Name: "n", @@ -2173,7 +2173,7 @@ func TestTeamsService_RemoveConnectedExternalGroup_notFound(t *testing.T) { func TestIDPGroupList_Marshal(t *testing.T) { t.Parallel() - testJSONMarshal(t, &IDPGroupList{}, "{}") + testJSONMarshal(t, &IDPGroupList{}, `{"groups": null}`) u := &IDPGroupList{ Groups: []*IDPGroup{ @@ -2301,27 +2301,6 @@ func TestExternalGroupTeam_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } -func TestListExternalGroupsOptions_Marshal(t *testing.T) { - t.Parallel() - testJSONMarshal(t, &ListExternalGroupsOptions{}, "{}") - - u := &ListExternalGroupsOptions{ - DisplayName: Ptr("test"), - ListOptions: ListOptions{ - Page: 1, - PerPage: 2, - }, - } - - want := `{ - "DisplayName": "test", - "page": 1, - "PerPage": 2 - }` - - testJSONMarshal(t, u, want) -} - func TestTeamAddTeamRepoOptions_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &TeamAddTeamRepoOptions{}, "{}") diff --git a/github/users_test.go b/github/users_test.go index ea3cb53bb30..7a2784744f3 100644 --- a/github/users_test.go +++ b/github/users_test.go @@ -492,34 +492,3 @@ func TestHovercard_Marshal(t *testing.T) { testJSONMarshal(t, h, want) } - -func TestUserListOptions_Marshal(t *testing.T) { - t.Parallel() - testJSONMarshal(t, &UserListOptions{}, "{}") - - u := &UserListOptions{Since: 1900, PerPage: 30} - - want := `{ - "since" : 1900, - "perPage": 30 - }` - - testJSONMarshal(t, u, want) -} - -func TestHovercardOptions_Marshal(t *testing.T) { - t.Parallel() - testJSONMarshal(t, &HovercardOptions{}, "{}") - - u := &HovercardOptions{ - SubjectType: "subjectType", - SubjectID: "subjectID", - } - - want := `{ - "SubjectType" : "subjectType", - "SubjectID" : "subjectID" - }` - - testJSONMarshal(t, u, want) -}