summaryrefslogtreecommitdiff
path: root/internal/funcs/conv_test.go
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2024-01-25 20:11:31 -0500
committerGitHub <noreply@github.com>2024-01-25 20:11:31 -0500
commitebb97fb7367fb983cffc1935a8fb57e4b80f5249 (patch)
tree43ef6cd01f629f60f59efe1e5b003f7c8e3a1257 /internal/funcs/conv_test.go
parentf1d9158ea99abbe556251c1ff2fe970f3b460ee9 (diff)
Move funcs package to internal (#1977)
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'internal/funcs/conv_test.go')
-rw-r--r--internal/funcs/conv_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/funcs/conv_test.go b/internal/funcs/conv_test.go
new file mode 100644
index 00000000..b20f013c
--- /dev/null
+++ b/internal/funcs/conv_test.go
@@ -0,0 +1,63 @@
+package funcs
+
+import (
+ "context"
+ "fmt"
+ "strconv"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestCreateConvFuncs(t *testing.T) {
+ t.Parallel()
+
+ for i := 0; i < 10; i++ {
+ // Run this a bunch to catch race conditions
+ t.Run(strconv.Itoa(i), func(t *testing.T) {
+ t.Parallel()
+
+ ctx := context.Background()
+ fmap := CreateConvFuncs(ctx)
+ actual := fmap["conv"].(func() interface{})
+
+ assert.Equal(t, ctx, actual().(*ConvFuncs).ctx)
+ })
+ }
+}
+
+func TestDefault(t *testing.T) {
+ t.Parallel()
+
+ s := struct{}{}
+ c := &ConvFuncs{}
+ def := "DEFAULT"
+ data := []struct {
+ val interface{}
+ empty bool
+ }{
+ {0, true},
+ {1, false},
+ {nil, true},
+ {"", true},
+ {"foo", false},
+ {[]string{}, true},
+ {[]string{"foo"}, false},
+ {[]string{""}, false},
+ {c, false},
+ {s, false},
+ }
+
+ for _, d := range data {
+ d := d
+ t.Run(fmt.Sprintf("%T/%#v empty==%v", d.val, d.val, d.empty), func(t *testing.T) {
+ t.Parallel()
+
+ if d.empty {
+ assert.Equal(t, def, c.Default(def, d.val))
+ } else {
+ assert.Equal(t, d.val, c.Default(def, d.val))
+ }
+ })
+ }
+}