Added duplicated trigger validation (#3124)
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
1e7805b790
Коммит
0d0734ac98
21
utils/utils.go
Обычный файл
21
utils/utils.go
Обычный файл
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package utils
|
||||
|
||||
func StringArrayIntersection(arr1, arr2 []string) []string {
|
||||
arrMap := map[string]bool{}
|
||||
result := []string{}
|
||||
|
||||
for _, value := range arr1 {
|
||||
arrMap[value] = true
|
||||
}
|
||||
|
||||
for _, value := range arr2 {
|
||||
if arrMap[value] {
|
||||
result = append(result, value)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
30
utils/utils_test.go
Обычный файл
30
utils/utils_test.go
Обычный файл
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStringArrayIntersection(t *testing.T) {
|
||||
a := []string{
|
||||
"abc",
|
||||
"def",
|
||||
"ghi",
|
||||
}
|
||||
b := []string{
|
||||
"jkl",
|
||||
}
|
||||
c := []string{
|
||||
"def",
|
||||
}
|
||||
|
||||
if len(StringArrayIntersection(a, b)) != 0 {
|
||||
t.Fatal("should be 0")
|
||||
}
|
||||
|
||||
if len(StringArrayIntersection(a, c)) != 1 {
|
||||
t.Fatal("should be 1")
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user