2020-05-06 15:53:47 +02:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2020-07-11 16:46:29 +02:00
|
|
|
"strings"
|
2020-05-06 15:53:47 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDirs(t *testing.T) {
|
|
|
|
t.Run("recursive", func(t *testing.T) {
|
2020-07-16 15:43:23 +02:00
|
|
|
result, err := Dirs("testdata", true, true)
|
2020-05-06 15:53:47 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:43:23 +02:00
|
|
|
assert.Contains(t, result, "/directory")
|
|
|
|
assert.Contains(t, result, "/directory/subdirectory")
|
|
|
|
assert.Contains(t, result, "/linked")
|
|
|
|
assert.Contains(t, result, "/linked/photoprism")
|
|
|
|
assert.Contains(t, result, "/linked/photoprism/sub")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("recursive no-symlinks", func(t *testing.T) {
|
|
|
|
result, err := Dirs("testdata", true, false)
|
2020-05-06 15:53:47 +02:00
|
|
|
|
2020-07-16 15:43:23 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Contains(t, result, "/directory")
|
|
|
|
assert.Contains(t, result, "/directory/subdirectory")
|
|
|
|
assert.Contains(t, result, "/linked")
|
2020-05-06 15:53:47 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("non-recursive", func(t *testing.T) {
|
2020-07-16 15:43:23 +02:00
|
|
|
result, err := Dirs("testdata", false, true)
|
2020-05-06 15:53:47 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:43:23 +02:00
|
|
|
assert.Contains(t, result, "/directory")
|
|
|
|
assert.Contains(t, result, "/linked")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("non-recursive no-symlinks", func(t *testing.T) {
|
|
|
|
result, err := Dirs("testdata/directory/subdirectory", false, false)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Contains(t, result, "/bar")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("non-recursive symlinks", func(t *testing.T) {
|
|
|
|
result, err := Dirs("testdata/linked", false, true)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Contains(t, result, "/photoprism")
|
|
|
|
assert.Contains(t, result, "/self")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no-result", func(t *testing.T) {
|
|
|
|
result, err := Dirs("testdata/linked", false, false)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-05-06 15:53:47 +02:00
|
|
|
|
2020-07-16 15:43:23 +02:00
|
|
|
assert.Empty(t, result)
|
2020-05-06 15:53:47 +02:00
|
|
|
})
|
|
|
|
}
|
2020-07-07 15:13:42 +02:00
|
|
|
|
|
|
|
func TestFindDirs(t *testing.T) {
|
|
|
|
t.Run("/directory", func(t *testing.T) {
|
|
|
|
result := FindDir([]string{"/directory", "/directory/subdirectory", "/linked"})
|
|
|
|
assert.Equal(t, "", result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("./testdata", func(t *testing.T) {
|
|
|
|
result := FindDir([]string{"./testdata"})
|
2020-07-11 16:46:29 +02:00
|
|
|
assert.True(t, strings.HasSuffix(result, "/pkg/fs/testdata"))
|
2020-07-07 15:13:42 +02:00
|
|
|
})
|
|
|
|
}
|