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

Change testJSONMarshal #2708

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
69 changes: 28 additions & 41 deletions github/actions_artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,25 +453,19 @@ func TestArtifact_Marshal(t *testing.T) {
},
}

want := `{
"id": 1,
"node_id": "nid",
"name": "n",
"size_in_bytes": 1,
"url": "u",
"archive_download_url": "a",
"expired": false,
"created_at": ` + referenceTimeStr + `,
"updated_at": ` + referenceTimeStr + `,
"expires_at": ` + referenceTimeStr + `,
"workflow_run": {
"id": 1,
"repository_id": 1,
"head_repository_id": 1,
"head_branch": "b",
"head_sha": "s"
}
}`
want := fmt.Sprint(
`{"id":1,`,
`"node_id":"nid",`,
`"name":"n",`,
`"size_in_bytes":1,`,
`"url":"u",`,
`"archive_download_url":"a",`,
`"expired":false,`,
`"created_at":`+referenceTimeStr+`,`,
`"updated_at":`+referenceTimeStr+`,`,
`"expires_at":`+referenceTimeStr+`,`,
`"workflow_run":{"id":1,"repository_id":1,"head_repository_id":1,"head_branch":"b","head_sha":"s"}}`,
)
exageraldo marked this conversation as resolved.
Show resolved Hide resolved

testJSONMarshal(t, u, want)
}
Expand Down Expand Up @@ -504,28 +498,21 @@ func TestArtifactList_Marshal(t *testing.T) {
},
}

want := `{
"total_count": 1,
"artifacts": [{
"id": 1,
"node_id": "nid",
"name": "n",
"size_in_bytes": 1,
"url": "u",
"archive_download_url": "a",
"expired": false,
"created_at": ` + referenceTimeStr + `,
"updated_at": ` + referenceTimeStr + `,
"expires_at": ` + referenceTimeStr + `,
"workflow_run": {
"id": 1,
"repository_id": 1,
"head_repository_id": 1,
"head_branch": "b",
"head_sha": "s"
}
}]
}`
want := fmt.Sprint(
`{"total_count":1,`,
`"artifacts":[`,
`{"id":1,`,
`"node_id":"nid",`,
`"name":"n",`,
`"size_in_bytes":1,`,
`"url":"u",`,
`"archive_download_url":"a",`,
`"expired":false,`,
`"created_at":`+referenceTimeStr+`,`,
`"updated_at":`+referenceTimeStr+`,`,
`"expires_at":`+referenceTimeStr+`,`,
`"workflow_run":{"id":1,"repository_id":1,"head_repository_id":1,"head_branch":"b","head_sha":"s"}}]}`,
)

testJSONMarshal(t, u, want)
}
105 changes: 49 additions & 56 deletions github/actions_runner_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,27 +544,27 @@ func TestRunnerGroup_Marshal(t *testing.T) {
Inherited: Bool(true),
AllowsPublicRepositories: Bool(true),
RestrictedToWorkflows: Bool(false),
SelectedWorkflows: []string{},
}

want := `{
"id": 1,
"name": "n",
"visibility": "v",
"default": true,
"selected_repositories_url": "s",
"runners_url": "r",
"inherited": true,
"allows_public_repositories": true,
"restricted_to_workflows": false,
"selected_workflows": []
}`
SelectedWorkflows: []string{"1"},
}

want := fmt.Sprint(
`{"id":1,`,
`"name":"n",`,
`"visibility":"v",`,
`"default":true,`,
`"selected_repositories_url":"s",`,
`"runners_url":"r",`,
`"inherited":true,`,
`"allows_public_repositories":true,`,
`"restricted_to_workflows":false,`,
`"selected_workflows":["1"]}`,
)

testJSONMarshal(t, u, want)
}

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

u := &RunnerGroups{
TotalCount: int(1),
Expand All @@ -579,26 +579,25 @@ func TestRunnerGroups_Marshal(t *testing.T) {
Inherited: Bool(true),
AllowsPublicRepositories: Bool(true),
RestrictedToWorkflows: Bool(false),
SelectedWorkflows: []string{},
SelectedWorkflows: []string{"1"},
},
},
}

want := `{
"total_count": 1,
"runner_groups": [{
"id": 1,
"name": "n",
"visibility": "v",
"default": true,
"selected_repositories_url": "s",
"runners_url": "r",
"inherited": true,
"allows_public_repositories": true,
"restricted_to_workflows": false,
"selected_workflows": []
}]
}`
want := fmt.Sprint(
`{"total_count":1,`,
`"runner_groups":[`,
`{"id":1,`,
`"name":"n",`,
`"visibility":"v",`,
`"default":true,`,
`"selected_repositories_url":"s",`,
`"runners_url":"r",`,
`"inherited":true,`,
`"allows_public_repositories":true,`,
`"restricted_to_workflows":false,`,
`"selected_workflows":["1"]}]}`,
)

testJSONMarshal(t, u, want)
}
Expand All @@ -616,15 +615,15 @@ func TestCreateRunnerGroupRequest_Marshal(t *testing.T) {
SelectedWorkflows: []string{"a", "b"},
}

want := `{
"name": "n",
"visibility": "v",
"selected_repository_ids": [1],
"runners": [1],
"allows_public_repositories": true,
"restricted_to_workflows": true,
"selected_workflows": ["a","b"]
}`
want := fmt.Sprint(
`{"name":"n",`,
`"visibility":"v",`,
`"selected_repository_ids":[1],`,
`"runners":[1],`,
`"allows_public_repositories":true,`,
`"restricted_to_workflows":true,`,
`"selected_workflows":["a","b"]}`,
)

testJSONMarshal(t, u, want)
}
Expand All @@ -640,41 +639,35 @@ func TestUpdateRunnerGroupRequest_Marshal(t *testing.T) {
SelectedWorkflows: []string{},
}

want := `{
"name": "n",
"visibility": "v",
"allows_public_repositories": true,
"restricted_to_workflows": false,
"selected_workflows": []
}`
want := `{"name":"n","visibility":"v","allows_public_repositories":true,"restricted_to_workflows":false}`

testJSONMarshal(t, u, want)
u.SelectedWorkflows = []string{"1"}
want = `{"name":"n","visibility":"v","allows_public_repositories":true,"restricted_to_workflows":false,"selected_workflows":["1"]}`

testJSONMarshal(t, u, want)
}

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

u := &SetRepoAccessRunnerGroupRequest{
SelectedRepositoryIDs: []int64{1},
}

want := `{
"selected_repository_ids": [1]
}`
want := `{"selected_repository_ids":[1]}`

testJSONMarshal(t, u, want)
}

func TestSetRunnerGroupRunnersRequest_Marshal(t *testing.T) {
testJSONMarshal(t, &SetRunnerGroupRunnersRequest{}, "{}")
testJSONMarshal(t, &SetRunnerGroupRunnersRequest{}, `{"runners":null}`)

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

want := `{
"runners": [1]
}`
want := `{"runners":[1]}`

testJSONMarshal(t, u, want)
}
75 changes: 9 additions & 66 deletions github/actions_runners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,20 +596,13 @@ func TestRunnerApplicationDownload_Marshal(t *testing.T) {
SHA256Checksum: String("s"),
}

want := `{
"os": "o",
"architecture": "a",
"download_url": "d",
"filename": "f",
"temp_download_token": "t",
"sha256_checksum": "s"
}`
want := `{"os":"o","architecture":"a","download_url":"d","filename":"f","temp_download_token":"t","sha256_checksum":"s"}`

testJSONMarshal(t, u, want)
}

func TestActionsEnabledOnOrgRepos_Marshal(t *testing.T) {
testJSONMarshal(t, &ActionsEnabledOnOrgRepos{}, "{}")
testJSONMarshal(t, &ActionsEnabledOnOrgRepos{}, `{"total_count":0,"repositories":null}`)

u := &ActionsEnabledOnOrgRepos{
TotalCount: 1,
Expand All @@ -622,16 +615,7 @@ func TestActionsEnabledOnOrgRepos_Marshal(t *testing.T) {
},
}

want := `{
"total_count": 1,
"repositories": [
{
"id": 1,
"url": "u",
"name": "n"
}
]
}`
want := `{"total_count":1,"repositories":[{"id":1,"name":"n","url":"u"}]}`

testJSONMarshal(t, u, want)
}
Expand All @@ -644,10 +628,7 @@ func TestRegistrationToken_Marshal(t *testing.T) {
ExpiresAt: &Timestamp{referenceTime},
}

want := `{
"token": "t",
"expires_at": ` + referenceTimeStr + `
}`
want := `{"token":"t","expires_at":` + referenceTimeStr + `}`

testJSONMarshal(t, u, want)
}
Expand All @@ -661,11 +642,7 @@ func TestRunnerLabels_Marshal(t *testing.T) {
Type: String("t"),
}

want := `{
"id": 1,
"name": "n",
"type": "t"
}`
want := `{"id":1,"name":"n","type":"t"}`

testJSONMarshal(t, u, want)
}
Expand All @@ -688,26 +665,13 @@ func TestRunner_Marshal(t *testing.T) {
},
}

want := `{
"id": 1,
"name": "n",
"os": "o",
"status": "s",
"busy": false,
"labels": [
{
"id": 1,
"name": "n",
"type": "t"
}
]
}`
want := `{"id":1,"name":"n","os":"o","status":"s","busy":false,"labels":[{"id":1,"name":"n","type":"t"}]}`

testJSONMarshal(t, u, want)
}

func TestRunners_Marshal(t *testing.T) {
testJSONMarshal(t, &Runners{}, "{}")
testJSONMarshal(t, &Runners{}, `{"total_count":0,"runners":null}`)

u := &Runners{
TotalCount: 1,
Expand All @@ -729,25 +693,7 @@ func TestRunners_Marshal(t *testing.T) {
},
}

want := `{
"total_count": 1,
"runners": [
{
"id": 1,
"name": "n",
"os": "o",
"status": "s",
"busy": false,
"labels": [
{
"id": 1,
"name": "n",
"type": "t"
}
]
}
]
}`
want := `{"total_count":1,"runners":[{"id":1,"name":"n","os":"o","status":"s","busy":false,"labels":[{"id":1,"name":"n","type":"t"}]}]}`

testJSONMarshal(t, u, want)
}
Expand All @@ -760,10 +706,7 @@ func TestRemoveToken_Marshal(t *testing.T) {
ExpiresAt: &Timestamp{referenceTime},
}

want := `{
"token": "t",
"expires_at": ` + referenceTimeStr + `
}`
want := `{"token":"t","expires_at":` + referenceTimeStr + `}`

testJSONMarshal(t, u, want)
}
Loading