mirror of https://github.com/portainer/portainer
fix(uac): ignore duplicates, spaces and casing in portainer labels (#4823)
* fix: ignore duplicates, spaces and casing in portainer labels * cleanup * fix: rebase errorpull/4484/head
parent
6c8276c65c
commit
f03cf2a6e4
@ -0,0 +1,63 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_getUniqueElements(t *testing.T) {
|
||||
cases := []struct {
|
||||
description string
|
||||
input string
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
description: "no items padded",
|
||||
input: " ",
|
||||
expected: []string{},
|
||||
},
|
||||
{
|
||||
description: "single item",
|
||||
input: "a",
|
||||
expected: []string{"a"},
|
||||
},
|
||||
{
|
||||
description: "single item padded",
|
||||
input: " a ",
|
||||
expected: []string{"a"},
|
||||
},
|
||||
{
|
||||
description: "multiple items",
|
||||
input: "a,b",
|
||||
expected: []string{"a", "b"},
|
||||
},
|
||||
{
|
||||
description: "multiple items padded",
|
||||
input: " a , b ",
|
||||
expected: []string{"a", "b"},
|
||||
},
|
||||
{
|
||||
description: "multiple items with empty values",
|
||||
input: " a , ,b ",
|
||||
expected: []string{"a", "b"},
|
||||
},
|
||||
{
|
||||
description: "duplicates",
|
||||
input: " a , a ",
|
||||
expected: []string{"a"},
|
||||
},
|
||||
{
|
||||
description: "mix with duplicates",
|
||||
input: " a ,b, a ",
|
||||
expected: []string{"a", "b"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
result := getUniqueElements(tt.input)
|
||||
assert.ElementsMatch(t, result, tt.expected)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in new issue