diff --git a/github/project.go b/github/project.go index d746fa874f8ea0c5c94c5ee4690971afb27876b8..39c35990d80a813ee80661fa6e7b0abcaeb25e22 100644 --- a/github/project.go +++ b/github/project.go @@ -23,9 +23,9 @@ func (p Project) String() string { } func (p *Project) SameAs(other *Project) bool { - return strings.ToLower(p.Owner) == strings.ToLower(other.Owner) && - strings.ToLower(p.Name) == strings.ToLower(other.Name) && - strings.ToLower(p.Host) == strings.ToLower(other.Host) + return strings.EqualFold(p.Owner, other.Owner) && + strings.EqualFold(p.Name, other.Name) && + strings.EqualFold(p.Host, other.Host) } func (p *Project) WebURL(name, owner, path string) string { diff --git a/github/project_test.go b/github/project_test.go index 5d1ff228a1c662a8d3f715d0c232cd2404a10899..83c71ac894de9e48e6e6e75866af0348ec4f3d67 100644 --- a/github/project_test.go +++ b/github/project_test.go @@ -9,6 +9,53 @@ import ( "github.com/github/hub/fixtures" ) +func TestSameAs(t *testing.T) { + tests := []struct { + name string + project1 *Project + project2 *Project + want bool + }{ + { + name: "same project", + project1: &Project{ + Owner: "fOo", + Name: "baR", + Host: "gItHUb.com", + }, + project2: &Project{ + Owner: "FoO", + Name: "BAr", + Host: "GithUB.com", + }, + want: true, + }, + { + name: "different project", + project1: &Project{ + Owner: "foo", + Name: "bar", + Host: "github.com", + }, + project2: &Project{ + Owner: "foo", + Name: "baz", + Host: "github.com", + }, + want: false, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + got := test.project1.SameAs(test.project2) + want := test.want + + assert.Equal(t, want, got) + }) + } +} + func TestProject_WebURL(t *testing.T) { project := Project{ Name: "foo",