Semaphore/services/project/backup_test.go

47 lines
681 B
Go

package project
import (
"testing"
)
type testItem struct {
Name string
}
func isUnique(items []testItem) bool {
for i, item := range items {
for k, other := range items {
if i == k {
continue
}
if item.Name == other.Name {
return false
}
}
}
return true
}
func TestMakeUniqueNames(t *testing.T) {
items := []testItem{
{Name: "Project"},
{Name: "Solution"},
{Name: "Project"},
{Name: "Project"},
{Name: "Project"},
{Name: "Project"},
}
makeUniqueNames(items, func(item *testItem) string {
return item.Name
}, func(item *testItem, name string) {
item.Name = name
})
if !isUnique(items) {
t.Fatal("Not unique names")
}
}