Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ linters:
- copyloopvar
- dogsled
- dupl
- forbidigo
- gocritic
- godot
- goheader
Expand Down Expand Up @@ -40,6 +41,10 @@ linters:

Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
forbidigo:
forbid:
- pattern: ^reflect\.DeepEqual$
msg: "Use cmp.Equal instead of reflect.DeepEqual"
gosec:
excludes:
# duplicates errcheck
Expand Down
2 changes: 1 addition & 1 deletion github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3186,7 +3186,7 @@ func TestPtr(t *testing.T) {
t.Parallel()
equal := func(t *testing.T, want, got any) {
t.Helper()
if !reflect.DeepEqual(want, got) {
if !cmp.Equal(want, got) {
t.Errorf("want %#v, got %#v", want, got)
}
}
Expand Down
25 changes: 13 additions & 12 deletions github/orgs_codesecurity_configurations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"

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

func TestOrganizationsService_GetCodeSecurityConfigurations(t *testing.T) {
Expand Down Expand Up @@ -43,7 +44,7 @@ func TestOrganizationsService_GetCodeSecurityConfigurations(t *testing.T) {
{ID: Ptr(int64(1)), Name: Ptr("config1"), CodeScanningDefaultSetup: Ptr("enabled")},
{ID: Ptr(int64(2)), Name: Ptr("config2"), PrivateVulnerabilityReporting: Ptr("enabled")},
}
if !reflect.DeepEqual(configurations, want) {
if !cmp.Equal(configurations, want) {
t.Errorf("Organizations.GetCodeSecurityConfigurations returned %+v, want %+v", configurations, want)
}
const methodName = "GetCodeSecurityConfigurations"
Expand Down Expand Up @@ -80,7 +81,7 @@ func TestOrganizationsService_GetCodeSecurityConfiguration(t *testing.T) {
}

want := &CodeSecurityConfiguration{ID: Ptr(int64(1)), Name: Ptr("config1"), CodeScanningDefaultSetup: Ptr("enabled")}
if !reflect.DeepEqual(configuration, want) {
if !cmp.Equal(configuration, want) {
t.Errorf("Organizations.GetCodeSecurityConfiguration returned %+v, want %+v", configuration, want)
}

Expand Down Expand Up @@ -113,7 +114,7 @@ func TestOrganizationsService_CreateCodeSecurityConfiguration(t *testing.T) {
v := new(CodeSecurityConfiguration)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

if !reflect.DeepEqual(v, input) {
if !cmp.Equal(v, input) {
t.Errorf("Organizations.CreateCodeSecurityConfiguration request body = %+v, want %+v", v, input)
}

Expand All @@ -130,7 +131,7 @@ func TestOrganizationsService_CreateCodeSecurityConfiguration(t *testing.T) {
}

want := &CodeSecurityConfiguration{ID: Ptr(int64(1)), Name: Ptr("config1"), CodeScanningDefaultSetup: Ptr("enabled")}
if !reflect.DeepEqual(configuration, want) {
if !cmp.Equal(configuration, want) {
t.Errorf("Organizations.CreateCodeSecurityConfiguration returned %+v, want %+v", configuration, want)
}

Expand Down Expand Up @@ -178,7 +179,7 @@ func TestOrganizationsService_GetDefaultCodeSecurityConfigurations(t *testing.T)
{ID: Ptr(int64(1)), Name: Ptr("config1"), CodeScanningDefaultSetup: Ptr("enabled")},
{ID: Ptr(int64(2)), Name: Ptr("config2"), PrivateVulnerabilityReporting: Ptr("enabled")},
}
if !reflect.DeepEqual(configurations, want) {
if !cmp.Equal(configurations, want) {
t.Errorf("Organizations.GetDefaultCodeSecurityConfigurations returned %+v, want %+v", configurations, want)
}

Expand Down Expand Up @@ -243,7 +244,7 @@ func TestOrganizationsService_UpdateCodeSecurityConfiguration(t *testing.T) {
v := new(CodeSecurityConfiguration)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

if !reflect.DeepEqual(v, input) {
if !cmp.Equal(v, input) {
t.Errorf("Organizations.UpdateCodeSecurityConfiguration request body = %+v, want %+v", v, input)
}

Expand All @@ -260,7 +261,7 @@ func TestOrganizationsService_UpdateCodeSecurityConfiguration(t *testing.T) {
}

want := &CodeSecurityConfiguration{ID: Ptr(int64(1)), Name: Ptr("config1"), CodeScanningDefaultSetup: Ptr("enabled")}
if !reflect.DeepEqual(configuration, want) {
if !cmp.Equal(configuration, want) {
t.Errorf("Organizations.UpdateCodeSecurityConfiguration returned %+v, want %+v", configuration, want)
}

Expand Down Expand Up @@ -327,7 +328,7 @@ func TestOrganizationsService_AttachCodeSecurityConfigurationsToRepositories(t *
if v.Scope != "selected" {
t.Errorf("Organizations.AttachCodeSecurityConfigurationsToRepositories request body scope = %s, want selected", v.Scope)
}
if !reflect.DeepEqual(v.SelectedRepositoryIDs, []int64{5, 20}) {
if !cmp.Equal(v.SelectedRepositoryIDs, []int64{5, 20}) {
t.Errorf("Organizations.AttachCodeSecurityConfigurationsToRepositories request body selected_repository_ids = %+v, want %+v", v.SelectedRepositoryIDs, []int64{5, 20})
}
w.WriteHeader(http.StatusAccepted)
Expand Down Expand Up @@ -387,7 +388,7 @@ func TestOrganizationsService_SetDefaultCodeSecurityConfiguration(t *testing.T)
ID: Ptr(int64(1)), Name: Ptr("config1"), CodeScanningDefaultSetup: Ptr("enabled"),
},
}
if !reflect.DeepEqual(got, want) {
if !cmp.Equal(got, want) {
t.Errorf("Organizations.SetDefaultCodeSecurityConfiguration returned %+v, want %+v", got, want)
}

Expand Down Expand Up @@ -433,7 +434,7 @@ func TestOrganizationsService_GetRepositoriesForCodeSecurityConfiguration(t *tes
{ID: Ptr(int64(8)), Name: Ptr("repo8")},
{ID: Ptr(int64(42)), Name: Ptr("repo42")},
}
if !reflect.DeepEqual(repositories, want) {
if !cmp.Equal(repositories, want) {
t.Errorf("Organizations.GetRepositoriesForCodeSecurityConfiguration returned %+v, want %+v", repositories, want)
}

Expand Down Expand Up @@ -478,7 +479,7 @@ func TestOrganizationsService_GetCodeSecurityConfigurationForRepository(t *testi
State: Ptr("attached"),
Configuration: c,
}
if !reflect.DeepEqual(rc, want) {
if !cmp.Equal(rc, want) {
t.Errorf("Organizations.GetCodeSecurityConfigurationForRepository returned %+v, want %+v", rc, want)
}

Expand Down
7 changes: 4 additions & 3 deletions github/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ package github

import (
"encoding/json"
"reflect"
"testing"

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

func TestPackageRegistry_Marshal(t *testing.T) {
Expand Down Expand Up @@ -556,7 +557,7 @@ func TestPackageVersion_GetBodyAsPackageVersionBody(t *testing.T) {

resValue, resOk := test.pv.GetBodyAsPackageVersionBody()

if !reflect.DeepEqual(resValue, test.wantValue) || resOk != test.wantOk {
if !cmp.Equal(resValue, test.wantValue) || resOk != test.wantOk {
t.Errorf("PackageVersion.GetBodyAsPackageVersionBody() - got: %v, %v; want: %v, %v", resValue, resOk, test.wantValue, test.wantOk)
}
})
Expand Down Expand Up @@ -615,7 +616,7 @@ func TestPackageVersion_GetMetadata(t *testing.T) {

resValue, resOk := test.pv.GetMetadata()

if !reflect.DeepEqual(resValue, test.wantValue) || resOk != test.wantOk {
if !cmp.Equal(resValue, test.wantValue) || resOk != test.wantOk {
t.Errorf("PackageVersion.GetMetadata() - got: %v, %v; want: %v, %v", resValue, resOk, test.wantValue, test.wantOk)
}
})
Expand Down
11 changes: 6 additions & 5 deletions github/repos_deployment_branch_policies_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 TestRepositoriesService_ListDeploymentBranchPolicies(t *testing.T) {
Expand All @@ -34,7 +35,7 @@ func TestRepositoriesService_ListDeploymentBranchPolicies(t *testing.T) {
},
TotalCount: Ptr(2),
}
if !reflect.DeepEqual(got, want) {
if !cmp.Equal(got, want) {
t.Errorf("Repositories.ListDeploymentBranchPolicies = %+v, want %+v", got, want)
}

Expand Down Expand Up @@ -63,7 +64,7 @@ func TestRepositoriesService_GetDeploymentBranchPolicy(t *testing.T) {
}

want := &DeploymentBranchPolicy{ID: Ptr(int64(1))}
if !reflect.DeepEqual(got, want) {
if !cmp.Equal(got, want) {
t.Errorf("Repositories.GetDeploymentBranchPolicy = %+v, want %+v", got, want)
}

Expand Down Expand Up @@ -93,7 +94,7 @@ func TestRepositoriesService_CreateDeploymentBranchPolicy(t *testing.T) {
}

want := &DeploymentBranchPolicy{ID: Ptr(int64(1)), Type: Ptr("branch")}
if !reflect.DeepEqual(got, want) {
if !cmp.Equal(got, want) {
t.Errorf("Repositories.CreateDeploymentBranchPolicy = %+v, want %+v", got, want)
}

Expand Down Expand Up @@ -123,7 +124,7 @@ func TestRepositoriesService_UpdateDeploymentBranchPolicy(t *testing.T) {
}

want := &DeploymentBranchPolicy{ID: Ptr(int64(1))}
if !reflect.DeepEqual(got, want) {
if !cmp.Equal(got, want) {
t.Errorf("Repositories.UpdateDeploymentBranchPolicy = %+v, want %+v", got, want)
}

Expand Down
11 changes: 5 additions & 6 deletions github/repos_deployment_protection_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -38,7 +37,7 @@ func TestRepositoriesService_GetAllDeploymentProtectionRules(t *testing.T) {
},
TotalCount: Ptr(2),
}
if !reflect.DeepEqual(got, want) {
if !cmp.Equal(got, want) {
t.Errorf("Repositories.GetAllDeploymentProtectionRules = %+v, want %+v", got, want)
}

Expand Down Expand Up @@ -66,7 +65,7 @@ func TestRepositoriesService_CreateCustomDeploymentProtectionRule(t *testing.T)

testMethod(t, r, "POST")
want := input
if !reflect.DeepEqual(v, want) {
if !cmp.Equal(v, want) {
t.Errorf("Request body = %+v, want %+v", v, want)
}

Expand All @@ -90,7 +89,7 @@ func TestRepositoriesService_CreateCustomDeploymentProtectionRule(t *testing.T)
IntegrationURL: Ptr("https://api.github.com/apps/a-custom-app"),
},
}
if !reflect.DeepEqual(got, want) {
if !cmp.Equal(got, want) {
t.Errorf("Repositories.CreateCustomDeploymentProtectionRule = %+v, want %+v", got, want)
}

Expand Down Expand Up @@ -131,7 +130,7 @@ func TestRepositoriesService_ListCustomDeploymentRuleIntegrations(t *testing.T)
{ID: Ptr(int64(2)), NodeID: Ptr("UHVE67RlcGxveW1lbnRTdTY!jfeuy"), Slug: Ptr("another-custom-app"), IntegrationURL: Ptr("https://api.github.com/apps/another-custom-app")},
},
}
if !reflect.DeepEqual(got, want) {
if !cmp.Equal(got, want) {
t.Errorf("Repositories.ListCustomDeploymentRuleIntegrations = %+v, want %+v", got, want)
}

Expand Down Expand Up @@ -172,7 +171,7 @@ func TestRepositoriesService_GetCustomDeploymentProtectionRule(t *testing.T) {
},
}

if !reflect.DeepEqual(got, want) {
if !cmp.Equal(got, want) {
t.Errorf("Repositories.GetCustomDeploymentProtectionRule = %+v, want %+v", got, want)
}

Expand Down
3 changes: 1 addition & 2 deletions github/repos_hooks_deliveries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -227,7 +226,7 @@ func TestHookDelivery_ParsePayload(t *testing.T) {
t.Error(err)
}

if !reflect.DeepEqual(obj, got) {
if !cmp.Equal(obj, got) {
t.Errorf("want %T %v, got %T %v", obj, obj, got, got)
}
})
Expand Down
Loading