mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
feat(app/edge-stacks): summarize the edge stack statuses in the backend (#818)
This commit is contained in:
parent
363a62d885
commit
e1c480d3c3
21 changed files with 645 additions and 312 deletions
46
api/slicesx/unique_test.go
Normal file
46
api/slicesx/unique_test.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package slicesx_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/portainer/portainer/api/slicesx"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_Unique(t *testing.T) {
|
||||
is := assert.New(t)
|
||||
t.Run("Should extract unique numbers", func(t *testing.T) {
|
||||
|
||||
source := []int{1, 1, 2, 3, 4, 4, 5, 4, 6, 7, 8, 9, 1}
|
||||
result := slicesx.Unique(source)
|
||||
expected := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||
|
||||
is.ElementsMatch(result, expected)
|
||||
})
|
||||
|
||||
t.Run("Should return empty array", func(t *testing.T) {
|
||||
source := []int{}
|
||||
result := slicesx.Unique(source)
|
||||
expected := []int{}
|
||||
is.ElementsMatch(result, expected)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_UniqueBy(t *testing.T) {
|
||||
is := assert.New(t)
|
||||
t.Run("Should extract unique numbers by property", func(t *testing.T) {
|
||||
|
||||
source := []struct{ int }{{1}, {1}, {2}, {3}, {4}, {4}, {5}, {4}, {6}, {7}, {8}, {9}, {1}}
|
||||
result := slicesx.UniqueBy(source, func(item struct{ int }) int { return item.int })
|
||||
expected := []struct{ int }{{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}}
|
||||
|
||||
is.ElementsMatch(result, expected)
|
||||
})
|
||||
|
||||
t.Run("Should return empty array", func(t *testing.T) {
|
||||
source := []int{}
|
||||
result := slicesx.UniqueBy(source, func(x int) int { return x })
|
||||
expected := []int{}
|
||||
is.ElementsMatch(result, expected)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue