argo-cd/util/notification/expression/strings/strings_test.go
Matthieu MOREL 53bc19b5f2
chore: enable unused-parameter from revive (#21365)
* chore: enable unused-parameter from revive

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

* apply recommandations

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

---------

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-01-07 10:12:56 -05:00

60 lines
1.1 KiB
Go

package strings
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewExprs(t *testing.T) {
funcs := []string{
"ReplaceAll",
"ToUpper",
"ToLower",
}
for _, fn := range funcs {
stringsExprs := NewExprs()
_, hasFunc := stringsExprs[fn]
assert.True(t, hasFunc)
}
}
func TestReplaceAll(t *testing.T) {
exprs := NewExprs()
input := "test_replace"
expected := "test=replace"
replaceAllFn, ok := exprs["ReplaceAll"].(func(s, old, new string) string)
assert.True(t, ok)
actual := replaceAllFn(input, "_", "=")
assert.Equal(t, expected, actual)
}
func TestUpperAndLower(t *testing.T) {
testCases := []struct {
fn string
input string
expected string
}{
{
fn: "ToUpper",
input: "test",
expected: "TEST",
},
{
fn: "ToLower",
input: "TEST",
expected: "test",
},
}
exprs := NewExprs()
for _, testCase := range testCases {
t.Run("With success case: Func: "+testCase.fn, func(t *testing.T) {
toUpperFn, ok := exprs[testCase.fn].(func(s string) string)
assert.True(t, ok)
actual := toUpperFn(testCase.input)
assert.Equal(t, testCase.expected, actual)
})
}
}