Skip to content

Commit

Permalink
WIP - Change testJSONMarshal and some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
exageraldo committed Mar 8, 2023
1 parent 099fae4 commit 9ec1b5a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 278 deletions.
43 changes: 2 additions & 41 deletions github/actions_artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,25 +453,7 @@ 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 := `{"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)
}
Expand Down Expand Up @@ -504,28 +486,7 @@ 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 := `{"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)
}
71 changes: 19 additions & 52 deletions github/actions_runner_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,24 +547,16 @@ func TestRunnerGroup_Marshal(t *testing.T) {
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": []
}`
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}`
testJSONMarshal(t, u, want)

u.SelectedWorkflows = []string{"1"}
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":["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 @@ -584,22 +576,11 @@ func TestRunnerGroups_Marshal(t *testing.T) {
},
}

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 := `{"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}]}`
testJSONMarshal(t, u, want)

u.RunnerGroups[0].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":["1"]}]}`
testJSONMarshal(t, u, want)
}

Expand All @@ -616,15 +597,7 @@ 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 := `{"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 +613,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

0 comments on commit 9ec1b5a

Please # to comment.