Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve testJSONMarshal #3519

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions github/actions_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand All @@ -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,
Expand Down
15 changes: 6 additions & 9 deletions github/actions_runner_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,16 +557,15 @@ func TestRunnerGroup_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)
}

func TestRunnerGroups_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &RunnerGroups{}, "{}")
testJSONMarshal(t, &RunnerGroups{}, `{"runner_groups": null, "total_count": 0}`)

u := &RunnerGroups{
TotalCount: int(1),
Expand Down Expand Up @@ -597,8 +596,7 @@ func TestRunnerGroups_Marshal(t *testing.T) {
"runners_url": "r",
"inherited": true,
"allows_public_repositories": true,
"restricted_to_workflows": false,
"selected_workflows": []
"restricted_to_workflows": false
}]
}`

Expand Down Expand Up @@ -648,16 +646,15 @@ func TestUpdateRunnerGroupRequest_Marshal(t *testing.T) {
"name": "n",
"visibility": "v",
"allows_public_repositories": true,
"restricted_to_workflows": false,
"selected_workflows": []
"restricted_to_workflows": false
}`

testJSONMarshal(t, u, want)
}

func TestSetRepoAccessRunnerGroupRequest_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &SetRepoAccessRunnerGroupRequest{}, "{}")
testJSONMarshal(t, &SetRepoAccessRunnerGroupRequest{}, `{"selected_repository_ids": null}`)

u := &SetRepoAccessRunnerGroupRequest{
SelectedRepositoryIDs: []int64{1},
Expand All @@ -672,7 +669,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},
Expand Down
7 changes: 5 additions & 2 deletions github/actions_runners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,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,
Expand Down Expand Up @@ -679,7 +682,7 @@ 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,
Expand Down
15 changes: 11 additions & 4 deletions github/actions_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,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"),
Expand All @@ -876,7 +879,11 @@ func TestPublicKey_Marshal(t *testing.T) {

func TestSecret_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &Secret{}, "{}")
testJSONMarshal(t, &Secret{}, `{
"created_at": `+emptyTimeStr+`,
"name": "",
"updated_at": `+emptyTimeStr+`
}`)

u := &Secret{
Name: "n",
Expand All @@ -899,7 +906,7 @@ func TestSecret_Marshal(t *testing.T) {

func TestSecrets_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &Secrets{}, "{}")
testJSONMarshal(t, &Secrets{}, `{"secrets": null, "total_count": 0}`)

u := &Secrets{
TotalCount: 1,
Expand Down Expand Up @@ -931,7 +938,7 @@ func TestSecrets_Marshal(t *testing.T) {

func TestEncryptedSecret_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &EncryptedSecret{}, "{}")
testJSONMarshal(t, &EncryptedSecret{}, `{"encrypted_value": "", "key_id": ""}`)

u := &EncryptedSecret{
Name: "n",
Expand Down
2 changes: 1 addition & 1 deletion github/actions_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ 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",
Expand Down
6 changes: 5 additions & 1 deletion github/actions_workflow_runs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,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",
Expand Down
2 changes: 1 addition & 1 deletion github/actions_workflows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,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]interface{}, 0)
inputs["key"] = "value"
Expand Down
2 changes: 1 addition & 1 deletion github/activity_notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func TestNotificationSubject_Marshal(t *testing.T) {

func TestMarkReadOptions_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &markReadOptions{}, "{}")
testJSONMarshal(t, &markReadOptions{}, `{"last_read_at": `+emptyTimeStr+`}`)

u := &markReadOptions{
LastReadAt: Timestamp{referenceTime},
Expand Down
2 changes: 1 addition & 1 deletion github/admin_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,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",
Expand Down
2 changes: 1 addition & 1 deletion github/apps_installation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,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),
Expand Down
12 changes: 10 additions & 2 deletions github/billing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@ func TestActionBilling_Marshal(t *testing.T) {

func TestPackageBilling_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &PackageBilling{}, "{}")
testJSONMarshal(t, &PackageBilling{}, `{
"included_gigabytes_bandwidth": 0,
"total_gigabytes_bandwidth_used": 0,
"total_paid_gigabytes_bandwidth_used": 0
}`)

u := &PackageBilling{
TotalGigabytesBandwidthUsed: 1,
Expand All @@ -415,7 +419,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,
Expand Down
12 changes: 8 additions & 4 deletions github/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,11 @@ func TestCheckRunImage_Marshal(t *testing.T) {

func TestCheckRunAction_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &CheckRunAction{}, "{}")
testJSONMarshal(t, &CheckRunAction{}, `{
"description": "",
"identifier": "",
"label": ""
}`)

u := &CheckRunAction{
Label: "l",
Expand Down Expand Up @@ -1051,7 +1055,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",
Expand Down Expand Up @@ -1131,7 +1135,7 @@ func TestCheckRunOutput_Marshal(t *testing.T) {

func TestCreateCheckRunOptions_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &CreateCheckRunOptions{}, "{}")
testJSONMarshal(t, &CreateCheckRunOptions{}, `{"head_sha": "", "name": ""}`)

u := &CreateCheckRunOptions{
Name: "n",
Expand Down Expand Up @@ -1228,7 +1232,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",
Expand Down
3 changes: 1 addition & 2 deletions github/dependabot_alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,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)
Expand Down
13 changes: 5 additions & 8 deletions github/enterprise_actions_runner_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,16 +557,15 @@ 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)
}

func TestEnterpriseRunnerGroups_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &EnterpriseRunnerGroups{}, "{}")
testJSONMarshal(t, &EnterpriseRunnerGroups{}, `{"runner_groups": null}`)

u := &EnterpriseRunnerGroups{
TotalCount: Ptr(1),
Expand Down Expand Up @@ -597,8 +596,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
}]
}`

Expand Down Expand Up @@ -648,16 +646,15 @@ func TestUpdateEnterpriseRunnerGroupRequest_Marshal(t *testing.T) {
"name": "n",
"visibility": "v",
"allows_public_repositories": true,
"restricted_to_workflows": false,
"selected_workflows": []
"restricted_to_workflows": false
}`

testJSONMarshal(t, u, want)
}

func TestSetOrgAccessRunnerGroupRequest_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &SetOrgAccessRunnerGroupRequest{}, "{}")
testJSONMarshal(t, &SetOrgAccessRunnerGroupRequest{}, `{"selected_organization_ids": null}`)

u := &SetOrgAccessRunnerGroupRequest{
SelectedOrganizationIDs: []int64{1},
Expand Down
Loading
Loading