2021-11-24 21:08:08 +05:30
|
|
|
package operators
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestMakeDynamicValuesCallback(t *testing.T) {
|
|
|
|
|
input := map[string][]string{
|
2022-02-23 13:54:46 +01:00
|
|
|
"a": {"1", "2"},
|
|
|
|
|
"b": {"3"},
|
|
|
|
|
"c": {},
|
|
|
|
|
"d": {"A", "B", "C"},
|
2021-11-24 21:08:08 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
count := 0
|
2021-11-24 22:40:17 +05:30
|
|
|
MakeDynamicValuesCallback(input, true, func(data map[string]interface{}) bool {
|
2021-11-24 21:08:08 +05:30
|
|
|
count++
|
|
|
|
|
require.Len(t, data, 3, "could not get correct output length")
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
require.Equal(t, 3, count, "could not get correct result count")
|
|
|
|
|
|
2021-11-24 22:40:17 +05:30
|
|
|
t.Run("all", func(t *testing.T) {
|
2021-11-24 21:08:08 +05:30
|
|
|
input := map[string][]string{
|
2022-02-23 13:54:46 +01:00
|
|
|
"a": {"1"},
|
|
|
|
|
"b": {"2"},
|
|
|
|
|
"c": {"3"},
|
2021-11-24 21:08:08 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
count := 0
|
2021-11-24 22:40:17 +05:30
|
|
|
MakeDynamicValuesCallback(input, true, func(data map[string]interface{}) bool {
|
|
|
|
|
count++
|
|
|
|
|
require.Len(t, data, 3, "could not get correct output length")
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
require.Equal(t, 1, count, "could not get correct result count")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("first", func(t *testing.T) {
|
|
|
|
|
input := map[string][]string{
|
2022-02-23 13:54:46 +01:00
|
|
|
"a": {"1", "2"},
|
|
|
|
|
"b": {"3"},
|
|
|
|
|
"c": {},
|
|
|
|
|
"d": {"A", "B", "C"},
|
2021-11-24 22:40:17 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
count := 0
|
|
|
|
|
MakeDynamicValuesCallback(input, false, func(data map[string]interface{}) bool {
|
2021-11-24 21:08:08 +05:30
|
|
|
count++
|
|
|
|
|
require.Len(t, data, 3, "could not get correct output length")
|
2021-11-24 21:56:55 +05:30
|
|
|
return false
|
2021-11-24 21:08:08 +05:30
|
|
|
})
|
|
|
|
|
require.Equal(t, 1, count, "could not get correct result count")
|
|
|
|
|
})
|
|
|
|
|
}
|