Skip to content

Commit

Permalink
fix: Updated comparisons in test files (#1875)
Browse files Browse the repository at this point in the history
Replaced all reflect.DeepEqual comparisons in test files with cmp.Equal.

Fixes: #1851
  • Loading branch information
sagar23sj committed May 26, 2021
1 parent 0318e77 commit 51e7595
Show file tree
Hide file tree
Showing 103 changed files with 848 additions and 744 deletions.
9 changes: 5 additions & 4 deletions github/actions_artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
"fmt"
"net/http"
"net/url"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
)

func TestActionsService_ListArtifacts(t *testing.T) {
Expand All @@ -37,7 +38,7 @@ func TestActionsService_ListArtifacts(t *testing.T) {
}

want := &ArtifactList{TotalCount: Int64(1), Artifacts: []*Artifact{{ID: Int64(1)}}}
if !reflect.DeepEqual(artifacts, want) {
if !cmp.Equal(artifacts, want) {
t.Errorf("Actions.ListArtifacts returned %+v, want %+v", artifacts, want)
}

Expand Down Expand Up @@ -119,7 +120,7 @@ func TestActionsService_ListWorkflowRunArtifacts(t *testing.T) {
}

want := &ArtifactList{TotalCount: Int64(1), Artifacts: []*Artifact{{ID: Int64(1)}}}
if !reflect.DeepEqual(artifacts, want) {
if !cmp.Equal(artifacts, want) {
t.Errorf("Actions.ListWorkflowRunArtifacts returned %+v, want %+v", artifacts, want)
}

Expand Down Expand Up @@ -206,7 +207,7 @@ func TestActionsService_GetArtifact(t *testing.T) {
SizeInBytes: Int64(5),
ArchiveDownloadURL: String("u"),
}
if !reflect.DeepEqual(artifact, want) {
if !cmp.Equal(artifact, want) {
t.Errorf("Actions.GetArtifact returned %+v, want %+v", artifact, want)
}

Expand Down
15 changes: 8 additions & 7 deletions github/actions_runner_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"context"
"fmt"
"net/http"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
)

func TestActionsService_ListOrganizationRunnerGroups(t *testing.T) {
Expand Down Expand Up @@ -38,7 +39,7 @@ func TestActionsService_ListOrganizationRunnerGroups(t *testing.T) {
{ID: Int64(3), Name: String("expensive-hardware"), Visibility: String("private"), Default: Bool(false), RunnersURL: String("https://api.github.com/orgs/octo-org/actions/runner_groups/3/runners"), Inherited: Bool(false), AllowsPublicRepositories: Bool(true)},
},
}
if !reflect.DeepEqual(groups, want) {
if !cmp.Equal(groups, want) {
t.Errorf("Actions.ListOrganizationRunnerGroups returned %+v, want %+v", groups, want)
}

Expand Down Expand Up @@ -83,7 +84,7 @@ func TestActionsService_GetOrganizationRunnerGroup(t *testing.T) {
AllowsPublicRepositories: Bool(true),
}

if !reflect.DeepEqual(group, want) {
if !cmp.Equal(group, want) {
t.Errorf("Actions.GetOrganizationRunnerGroup returned %+v, want %+v", group, want)
}

Expand Down Expand Up @@ -157,7 +158,7 @@ func TestActionsService_CreateOrganizationRunnerGroup(t *testing.T) {
AllowsPublicRepositories: Bool(true),
}

if !reflect.DeepEqual(group, want) {
if !cmp.Equal(group, want) {
t.Errorf("Actions.CreateOrganizationRunnerGroup returned %+v, want %+v", group, want)
}

Expand Down Expand Up @@ -206,7 +207,7 @@ func TestActionsService_UpdateOrganizationRunnerGroup(t *testing.T) {
AllowsPublicRepositories: Bool(true),
}

if !reflect.DeepEqual(group, want) {
if !cmp.Equal(group, want) {
t.Errorf("Actions.UpdateOrganizationRunnerGroup returned %+v, want %+v", group, want)
}

Expand Down Expand Up @@ -246,7 +247,7 @@ func TestActionsService_ListRepositoryAccessRunnerGroup(t *testing.T) {
{ID: Int64(43), NodeID: String("MDEwOlJlcG9zaXRvcnkxMjk2MjY5"), Name: String("Hello-World"), FullName: String("octocat/Hello-World")},
},
}
if !reflect.DeepEqual(groups, want) {
if !cmp.Equal(groups, want) {
t.Errorf("Actions.ListRepositoryAccessRunnerGroup returned %+v, want %+v", groups, want)
}

Expand Down Expand Up @@ -371,7 +372,7 @@ func TestActionsService_ListRunerGroupRunners(t *testing.T) {
{ID: Int64(24), Name: String("iMac"), OS: String("macos"), Status: String("offline")},
},
}
if !reflect.DeepEqual(runners, want) {
if !cmp.Equal(runners, want) {
t.Errorf("Actions.ListRunerGroupRunners returned %+v, want %+v", runners, want)
}

Expand Down
25 changes: 13 additions & 12 deletions github/actions_runners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"context"
"fmt"
"net/http"
"reflect"
"testing"
"time"

"github.com/google/go-cmp/cmp"
)

func TestActionsService_ListRunnerApplicationDownloads(t *testing.T) {
Expand All @@ -36,7 +37,7 @@ func TestActionsService_ListRunnerApplicationDownloads(t *testing.T) {
{OS: String("win"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip"), Filename: String("actions-runner-win-x64-2.164.0.zip")},
{OS: String("linux"), Architecture: String("arm64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm64-2.164.0.tar.gz")},
}
if !reflect.DeepEqual(downloads, want) {
if !cmp.Equal(downloads, want) {
t.Errorf("Actions.ListRunnerApplicationDownloads returned %+v, want %+v", downloads, want)
}

Expand Down Expand Up @@ -73,7 +74,7 @@ func TestActionsService_CreateRegistrationToken(t *testing.T) {
want := &RegistrationToken{Token: String("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"),
ExpiresAt: &Timestamp{time.Date(2020, time.January, 22, 12, 13, 35,
123000000, time.UTC)}}
if !reflect.DeepEqual(token, want) {
if !cmp.Equal(token, want) {
t.Errorf("Actions.CreateRegistrationToken returned %+v, want %+v", token, want)
}

Expand Down Expand Up @@ -116,7 +117,7 @@ func TestActionsService_ListRunners(t *testing.T) {
{ID: Int64(24), Name: String("iMac"), OS: String("macos"), Status: String("offline")},
},
}
if !reflect.DeepEqual(runners, want) {
if !cmp.Equal(runners, want) {
t.Errorf("Actions.ListRunners returned %+v, want %+v", runners, want)
}

Expand Down Expand Up @@ -156,7 +157,7 @@ func TestActionsService_GetRunner(t *testing.T) {
OS: String("macos"),
Status: String("online"),
}
if !reflect.DeepEqual(runner, want) {
if !cmp.Equal(runner, want) {
t.Errorf("Actions.GetRunner returned %+v, want %+v", runner, want)
}

Expand Down Expand Up @@ -191,7 +192,7 @@ func TestActionsService_CreateRemoveToken(t *testing.T) {
}

want := &RemoveToken{Token: String("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &Timestamp{time.Date(2020, time.January, 29, 12, 13, 35, 123000000, time.UTC)}}
if !reflect.DeepEqual(token, want) {
if !cmp.Equal(token, want) {
t.Errorf("Actions.CreateRemoveToken returned %+v, want %+v", token, want)
}

Expand Down Expand Up @@ -257,7 +258,7 @@ func TestActionsService_ListOrganizationRunnerApplicationDownloads(t *testing.T)
{OS: String("win"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip"), Filename: String("actions-runner-win-x64-2.164.0.zip")},
{OS: String("linux"), Architecture: String("arm64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm64-2.164.0.tar.gz")},
}
if !reflect.DeepEqual(downloads, want) {
if !cmp.Equal(downloads, want) {
t.Errorf("Actions.ListOrganizationRunnerApplicationDownloads returned %+v, want %+v", downloads, want)
}

Expand Down Expand Up @@ -294,7 +295,7 @@ func TestActionsService_CreateOrganizationRegistrationToken(t *testing.T) {
want := &RegistrationToken{Token: String("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"),
ExpiresAt: &Timestamp{time.Date(2020, time.January, 22, 12, 13, 35,
123000000, time.UTC)}}
if !reflect.DeepEqual(token, want) {
if !cmp.Equal(token, want) {
t.Errorf("Actions.CreateRegistrationToken returned %+v, want %+v", token, want)
}

Expand Down Expand Up @@ -337,7 +338,7 @@ func TestActionsService_ListOrganizationRunners(t *testing.T) {
{ID: Int64(24), Name: String("iMac"), OS: String("macos"), Status: String("offline")},
},
}
if !reflect.DeepEqual(runners, want) {
if !cmp.Equal(runners, want) {
t.Errorf("Actions.ListRunners returned %+v, want %+v", runners, want)
}

Expand Down Expand Up @@ -381,7 +382,7 @@ func TestActionsService_ListEnabledReposInOrg(t *testing.T) {
{ID: Int64(2)},
{ID: Int64(3)},
}}
if !reflect.DeepEqual(got, want) {
if !cmp.Equal(got, want) {
t.Errorf("Actions.ListEnabledReposInOrg returned %+v, want %+v", got, want)
}

Expand Down Expand Up @@ -421,7 +422,7 @@ func TestActionsService_GetOrganizationRunner(t *testing.T) {
OS: String("macos"),
Status: String("online"),
}
if !reflect.DeepEqual(runner, want) {
if !cmp.Equal(runner, want) {
t.Errorf("Actions.GetRunner returned %+v, want %+v", runner, want)
}

Expand Down Expand Up @@ -456,7 +457,7 @@ func TestActionsService_CreateOrganizationRemoveToken(t *testing.T) {
}

want := &RemoveToken{Token: String("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &Timestamp{time.Date(2020, time.January, 29, 12, 13, 35, 123000000, time.UTC)}}
if !reflect.DeepEqual(token, want) {
if !cmp.Equal(token, want) {
t.Errorf("Actions.CreateRemoveToken returned %+v, want %+v", token, want)
}

Expand Down
29 changes: 15 additions & 14 deletions github/actions_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
"time"

"github.com/google/go-cmp/cmp"
)

func TestPublicKey_UnmarshalJSON(t *testing.T) {
Expand Down Expand Up @@ -84,7 +85,7 @@ func TestPublicKey_UnmarshalJSON(t *testing.T) {
if err != nil && !tt.wantErr {
t.Errorf("PublicKey.UnmarshalJSON returned an unexpected error: %+v", err)
}
if !reflect.DeepEqual(tt.wantPublicKey, pk) {
if !cmp.Equal(tt.wantPublicKey, pk) {
t.Errorf("PublicKey.UnmarshalJSON expected public key %+v, got %+v", tt.wantPublicKey, pk)
}
})
Expand All @@ -107,7 +108,7 @@ func TestActionsService_GetRepoPublicKey(t *testing.T) {
}

want := &PublicKey{KeyID: String("1234"), Key: String("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234")}
if !reflect.DeepEqual(key, want) {
if !cmp.Equal(key, want) {
t.Errorf("Actions.GetRepoPublicKey returned %+v, want %+v", key, want)
}

Expand Down Expand Up @@ -142,7 +143,7 @@ func TestActionsService_GetRepoPublicKeyNumeric(t *testing.T) {
}

want := &PublicKey{KeyID: String("1234"), Key: String("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234")}
if !reflect.DeepEqual(key, want) {
if !cmp.Equal(key, want) {
t.Errorf("Actions.GetRepoPublicKey returned %+v, want %+v", key, want)
}

Expand Down Expand Up @@ -185,7 +186,7 @@ func TestActionsService_ListRepoSecrets(t *testing.T) {
{Name: "B", CreatedAt: Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
},
}
if !reflect.DeepEqual(secrets, want) {
if !cmp.Equal(secrets, want) {
t.Errorf("Actions.ListRepoSecrets returned %+v, want %+v", secrets, want)
}

Expand Down Expand Up @@ -224,7 +225,7 @@ func TestActionsService_GetRepoSecret(t *testing.T) {
CreatedAt: Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)},
UpdatedAt: Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)},
}
if !reflect.DeepEqual(secret, want) {
if !cmp.Equal(secret, want) {
t.Errorf("Actions.GetRepoSecret returned %+v, want %+v", secret, want)
}

Expand Down Expand Up @@ -317,7 +318,7 @@ func TestActionsService_GetOrgPublicKey(t *testing.T) {
}

want := &PublicKey{KeyID: String("012345678"), Key: String("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234")}
if !reflect.DeepEqual(key, want) {
if !cmp.Equal(key, want) {
t.Errorf("Actions.GetOrgPublicKey returned %+v, want %+v", key, want)
}

Expand Down Expand Up @@ -361,7 +362,7 @@ func TestActionsService_ListOrgSecrets(t *testing.T) {
{Name: "GH_TOKEN", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: "selected", SelectedRepositoriesURL: "https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories"},
},
}
if !reflect.DeepEqual(secrets, want) {
if !cmp.Equal(secrets, want) {
t.Errorf("Actions.ListOrgSecrets returned %+v, want %+v", secrets, want)
}

Expand Down Expand Up @@ -402,7 +403,7 @@ func TestActionsService_GetOrgSecret(t *testing.T) {
Visibility: "selected",
SelectedRepositoriesURL: "https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories",
}
if !reflect.DeepEqual(secret, want) {
if !cmp.Equal(secret, want) {
t.Errorf("Actions.GetOrgSecret returned %+v, want %+v", secret, want)
}

Expand Down Expand Up @@ -477,7 +478,7 @@ func TestActionsService_ListSelectedReposForOrgSecret(t *testing.T) {
{ID: Int64(1)},
},
}
if !reflect.DeepEqual(repos, want) {
if !cmp.Equal(repos, want) {
t.Errorf("Actions.ListSelectedReposForOrgSecret returned %+v, want %+v", repos, want)
}

Expand Down Expand Up @@ -615,7 +616,7 @@ func TestActionsService_GetEnvPublicKey(t *testing.T) {
}

want := &PublicKey{KeyID: String("1234"), Key: String("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234")}
if !reflect.DeepEqual(key, want) {
if !cmp.Equal(key, want) {
t.Errorf("Actions.GetEnvPublicKey returned %+v, want %+v", key, want)
}

Expand Down Expand Up @@ -650,7 +651,7 @@ func TestActionsService_GetEnvPublicKeyNumeric(t *testing.T) {
}

want := &PublicKey{KeyID: String("1234"), Key: String("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234")}
if !reflect.DeepEqual(key, want) {
if !cmp.Equal(key, want) {
t.Errorf("Actions.GetEnvPublicKey returned %+v, want %+v", key, want)
}

Expand Down Expand Up @@ -693,7 +694,7 @@ func TestActionsService_ListEnvSecrets(t *testing.T) {
{Name: "B", CreatedAt: Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
},
}
if !reflect.DeepEqual(secrets, want) {
if !cmp.Equal(secrets, want) {
t.Errorf("Actions.ListEnvSecrets returned %+v, want %+v", secrets, want)
}

Expand Down Expand Up @@ -732,7 +733,7 @@ func TestActionsService_GetEnvSecret(t *testing.T) {
CreatedAt: Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)},
UpdatedAt: Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)},
}
if !reflect.DeepEqual(secret, want) {
if !cmp.Equal(secret, want) {
t.Errorf("Actions.GetEnvSecret returned %+v, want %+v", secret, want)
}

Expand Down
9 changes: 5 additions & 4 deletions github/actions_workflow_jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"fmt"
"net/http"
"net/url"
"reflect"
"testing"
"time"

"github.com/google/go-cmp/cmp"
)

func TestActionsService_ListWorkflowJobs(t *testing.T) {
Expand All @@ -39,7 +40,7 @@ func TestActionsService_ListWorkflowJobs(t *testing.T) {
{ID: Int64(399444497), RunID: Int64(29679449), StartedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, CompletedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
},
}
if !reflect.DeepEqual(jobs, want) {
if !cmp.Equal(jobs, want) {
t.Errorf("Actions.ListWorkflowJobs returned %+v, want %+v", jobs, want)
}

Expand Down Expand Up @@ -82,7 +83,7 @@ func TestActionsService_ListWorkflowJobs_Filter(t *testing.T) {
{ID: Int64(399444497), RunID: Int64(29679449), StartedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, CompletedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
},
}
if !reflect.DeepEqual(jobs, want) {
if !cmp.Equal(jobs, want) {
t.Errorf("Actions.ListWorkflowJobs returned %+v, want %+v", jobs, want)
}
}
Expand All @@ -107,7 +108,7 @@ func TestActionsService_GetWorkflowJobByID(t *testing.T) {
StartedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)},
CompletedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)},
}
if !reflect.DeepEqual(job, want) {
if !cmp.Equal(job, want) {
t.Errorf("Actions.GetWorkflowJobByID returned %+v, want %+v", job, want)
}

Expand Down
Loading

0 comments on commit 51e7595

Please sign in to comment.