summaryrefslogtreecommitdiff
path: root/internal/funcs/path_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/path_test.go
parentf1d9158ea99abbe556251c1ff2fe970f3b460ee9 (diff)
Move funcs package to internal (#1977)
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'internal/funcs/path_test.go')
-rw-r--r--internal/funcs/path_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/funcs/path_test.go b/internal/funcs/path_test.go
new file mode 100644
index 00000000..a314933b
--- /dev/null
+++ b/internal/funcs/path_test.go
@@ -0,0 +1,46 @@
+package funcs
+
+import (
+ "context"
+ "strconv"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestCreatePathFuncs(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 := CreatePathFuncs(ctx)
+ actual := fmap["path"].(func() interface{})
+
+ assert.Equal(t, ctx, actual().(*PathFuncs).ctx)
+ })
+ }
+}
+
+func TestPathFuncs(t *testing.T) {
+ t.Parallel()
+
+ p := PathFuncs{}
+ assert.Equal(t, "bar", p.Base("foo/bar"))
+ assert.Equal(t, "bar", p.Base("/foo/bar"))
+
+ assert.Equal(t, "/foo/baz", p.Clean("/foo/bar/../baz"))
+ assert.Equal(t, "foo", p.Dir("foo/bar"))
+ assert.Equal(t, ".txt", p.Ext("/foo/bar/baz.txt"))
+ assert.False(t, false, p.IsAbs("foo/bar"))
+ assert.True(t, p.IsAbs("/foo/bar"))
+ assert.Equal(t, "foo/bar/qux", p.Join("foo", "bar", "baz", "..", "qux"))
+ m, _ := p.Match("*.txt", "foo.json")
+ assert.False(t, m)
+ m, _ = p.Match("*.txt", "foo.txt")
+ assert.True(t, m)
+ assert.Equal(t, []string{"/foo/bar/", "baz"}, p.Split("/foo/bar/baz"))
+}