refactor: use slices.Equal to simplify code (#11364)
Signed-off-by: minxinyi <minxinyi6@outlook.com>
This commit is contained in:
parent
4e1318eb2a
commit
21b08bdd20
2 changed files with 10 additions and 34 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
|
@ -164,7 +165,7 @@ func Test_RepoMetadata(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("error resolving members: %v", err)
|
||||
}
|
||||
if !sliceEqual(memberIDs, expectedMemberIDs) {
|
||||
if !slices.Equal(memberIDs, expectedMemberIDs) {
|
||||
t.Errorf("expected members %v, got %v", expectedMemberIDs, memberIDs)
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +174,7 @@ func Test_RepoMetadata(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("error resolving teams: %v", err)
|
||||
}
|
||||
if !sliceEqual(teamIDs, expectedTeamIDs) {
|
||||
if !slices.Equal(teamIDs, expectedTeamIDs) {
|
||||
t.Errorf("expected teams %v, got %v", expectedTeamIDs, teamIDs)
|
||||
}
|
||||
|
||||
|
|
@ -182,7 +183,7 @@ func Test_RepoMetadata(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("error resolving labels: %v", err)
|
||||
}
|
||||
if !sliceEqual(labelIDs, expectedLabelIDs) {
|
||||
if !slices.Equal(labelIDs, expectedLabelIDs) {
|
||||
t.Errorf("expected labels %v, got %v", expectedLabelIDs, labelIDs)
|
||||
}
|
||||
|
||||
|
|
@ -192,10 +193,10 @@ func Test_RepoMetadata(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("error resolving projects: %v", err)
|
||||
}
|
||||
if !sliceEqual(projectIDs, expectedProjectIDs) {
|
||||
if !slices.Equal(projectIDs, expectedProjectIDs) {
|
||||
t.Errorf("expected projects %v, got %v", expectedProjectIDs, projectIDs)
|
||||
}
|
||||
if !sliceEqual(projectV2IDs, expectedProjectV2IDs) {
|
||||
if !slices.Equal(projectV2IDs, expectedProjectV2IDs) {
|
||||
t.Errorf("expected projectsV2 %v, got %v", expectedProjectV2IDs, projectV2IDs)
|
||||
}
|
||||
|
||||
|
|
@ -317,7 +318,7 @@ func Test_ProjectNamesToPaths(t *testing.T) {
|
|||
}
|
||||
|
||||
expectedProjectPaths := []string{"ORG/1", "OWNER/REPO/2", "ORG/2", "OWNER/REPO/4", "MONALISA/5"}
|
||||
if !sliceEqual(projectPaths, expectedProjectPaths) {
|
||||
if !slices.Equal(projectPaths, expectedProjectPaths) {
|
||||
t.Errorf("expected projects paths %v, got %v", expectedProjectPaths, projectPaths)
|
||||
}
|
||||
})
|
||||
|
|
@ -375,7 +376,7 @@ func Test_ProjectNamesToPaths(t *testing.T) {
|
|||
}
|
||||
|
||||
expectedProjectPaths := []string{"ORG/2", "OWNER/REPO/4", "MONALISA/5"}
|
||||
if !sliceEqual(projectPaths, expectedProjectPaths) {
|
||||
if !slices.Equal(projectPaths, expectedProjectPaths) {
|
||||
t.Errorf("expected projects paths %v, got %v", expectedProjectPaths, projectPaths)
|
||||
}
|
||||
})
|
||||
|
|
@ -489,20 +490,6 @@ func TestMembersToIDs(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func sliceEqual(a, b []string) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := range a {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func Test_RepoMilestones(t *testing.T) {
|
||||
tests := []struct {
|
||||
state string
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -322,7 +323,7 @@ func TestDelete(t *testing.T) {
|
|||
gotDeleted = append(gotDeleted, delArgs.Name)
|
||||
}
|
||||
sort.Strings(gotDeleted)
|
||||
if !sliceEquals(gotDeleted, tt.wantDeleted) {
|
||||
if !slices.Equal(gotDeleted, tt.wantDeleted) {
|
||||
t.Errorf("deleted %q, want %q", gotDeleted, tt.wantDeleted)
|
||||
}
|
||||
if out := stdout.String(); out != tt.wantStdout {
|
||||
|
|
@ -335,18 +336,6 @@ func TestDelete(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func sliceEquals(a, b []string) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i := range a {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func sortLines(s string) string {
|
||||
trailing := ""
|
||||
if strings.HasSuffix(s, "\n") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue