2020-05-03 14:40:59 +02:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2020-06-07 10:09:35 +02:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2020-05-03 14:40:59 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-06-07 10:09:35 +02:00
|
|
|
func TestRel(t *testing.T) {
|
2020-05-22 19:05:16 +02:00
|
|
|
t.Run("same", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
assert.Equal(t, "", RelName("/some/path", "/some/path"))
|
2020-05-22 19:05:16 +02:00
|
|
|
})
|
|
|
|
t.Run("short", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
assert.Equal(t, "/some/", RelName("/some/", "/some/path"))
|
2020-05-22 19:05:16 +02:00
|
|
|
})
|
|
|
|
t.Run("empty", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
assert.Equal(t, "", RelName("", "/some/path"))
|
2020-05-22 19:05:16 +02:00
|
|
|
})
|
2020-05-03 14:40:59 +02:00
|
|
|
t.Run("/some/path", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
assert.Equal(t, "foo/bar.baz", RelName("/some/path/foo/bar.baz", "/some/path"))
|
2020-05-03 14:40:59 +02:00
|
|
|
})
|
|
|
|
t.Run("/some/path/", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
assert.Equal(t, "foo/bar.baz", RelName("/some/path/foo/bar.baz", "/some/path/"))
|
2020-05-03 14:40:59 +02:00
|
|
|
})
|
|
|
|
t.Run("/some/path/bar", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
assert.Equal(t, "/some/path/foo/bar.baz", RelName("/some/path/foo/bar.baz", "/some/path/bar"))
|
2020-06-07 10:09:35 +02:00
|
|
|
})
|
2020-07-07 15:13:42 +02:00
|
|
|
t.Run("empty dir", func(t *testing.T) {
|
2020-07-14 11:00:49 +02:00
|
|
|
assert.Equal(t, "/some/path/foo/bar.baz", RelName("/some/path/foo/bar.baz", ""))
|
2020-07-07 15:13:42 +02:00
|
|
|
})
|
2020-06-07 10:09:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFileName(t *testing.T) {
|
|
|
|
t.Run("Test copy 3.jpg", func(t *testing.T) {
|
2020-12-12 13:05:58 +01:00
|
|
|
result := FileName("testdata/Test (4).jpg", ".photoprism", Abs("testdata"), ".xmp")
|
2020-06-07 10:09:35 +02:00
|
|
|
|
2020-12-12 13:05:58 +01:00
|
|
|
assert.Equal(t, "testdata/.photoprism/Test (4).jpg.xmp", result)
|
2020-06-07 10:09:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test (3).jpg", func(t *testing.T) {
|
2020-12-12 13:05:58 +01:00
|
|
|
result := FileName("testdata/Test (4).jpg", ".photoprism", Abs("testdata"), ".xmp")
|
2020-06-07 10:09:35 +02:00
|
|
|
|
2020-12-12 13:05:58 +01:00
|
|
|
assert.Equal(t, "testdata/.photoprism/Test (4).jpg.xmp", result)
|
2020-06-07 10:09:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("FOO.XMP", func(t *testing.T) {
|
2020-12-12 13:05:58 +01:00
|
|
|
result := FileName("testdata/FOO.XMP", ".photoprism/sub", Abs("testdata"), ".jpeg")
|
2020-06-07 10:09:35 +02:00
|
|
|
|
2020-12-12 13:05:58 +01:00
|
|
|
assert.Equal(t, "testdata/.photoprism/sub/FOO.XMP.jpeg", result)
|
2020-06-07 10:09:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test copy 3.jpg", func(t *testing.T) {
|
|
|
|
tempDir := filepath.Join(os.TempDir(), HiddenPath)
|
|
|
|
|
|
|
|
// t.Logf("TEMP DIR, ABS NAME: %s, %s", tempDir, Abs("testdata/Test (4).jpg"))
|
|
|
|
|
2020-12-12 13:05:58 +01:00
|
|
|
result := FileName(Abs("testdata/Test (4).jpg"), tempDir, Abs("testdata"), ".xmp")
|
2020-06-07 10:09:35 +02:00
|
|
|
|
2020-12-12 13:05:58 +01:00
|
|
|
assert.Equal(t, tempDir+"/Test (4).jpg.xmp", result)
|
2020-05-03 14:40:59 +02:00
|
|
|
})
|
2020-07-07 15:13:42 +02:00
|
|
|
|
|
|
|
t.Run("empty dir", func(t *testing.T) {
|
2020-12-12 13:05:58 +01:00
|
|
|
result := FileName("testdata/FOO.XMP", "", Abs("testdata"), ".jpeg")
|
2020-07-07 15:13:42 +02:00
|
|
|
|
2020-12-12 13:05:58 +01:00
|
|
|
assert.Equal(t, "testdata/FOO.XMP.jpeg", result)
|
2020-07-07 15:13:42 +02:00
|
|
|
})
|
2020-05-03 14:40:59 +02:00
|
|
|
}
|
2021-09-24 01:24:36 +02:00
|
|
|
|
|
|
|
func TestFileNameHidden(t *testing.T) {
|
|
|
|
t.Run("AtPrefix", func(t *testing.T) {
|
|
|
|
assert.True(t, FileNameHidden("/some/path/@eaDir"))
|
|
|
|
})
|
2022-11-02 17:23:59 +01:00
|
|
|
t.Run("Dot", func(t *testing.T) {
|
2021-09-24 01:24:36 +02:00
|
|
|
assert.True(t, FileNameHidden("/some/.folder"))
|
|
|
|
})
|
2022-11-02 17:23:59 +01:00
|
|
|
|
|
|
|
t.Run("Dots", func(t *testing.T) {
|
|
|
|
assert.False(t, FileNameHidden("/some/image.jpg."))
|
|
|
|
assert.False(t, FileNameHidden("./.some/foo"))
|
|
|
|
})
|
|
|
|
t.Run("Underscore", func(t *testing.T) {
|
|
|
|
assert.False(t, FileNameHidden("/some/_folder"))
|
|
|
|
assert.False(t, FileNameHidden("_folder"))
|
|
|
|
assert.True(t, FileNameHidden("/some/_.folder"))
|
|
|
|
assert.True(t, FileNameHidden("_.folder"))
|
2022-11-02 18:02:18 +01:00
|
|
|
assert.True(t, FileNameHidden("/some/__MACOSX"))
|
|
|
|
assert.True(t, FileNameHidden("__MACOSX"))
|
2022-11-02 17:23:59 +01:00
|
|
|
})
|
|
|
|
t.Run("At", func(t *testing.T) {
|
2021-09-24 01:24:36 +02:00
|
|
|
assert.False(t, FileNameHidden("/some/path/ea@Dir"))
|
|
|
|
assert.False(t, FileNameHidden("/some/@path/ea@Dir"))
|
|
|
|
assert.False(t, FileNameHidden("@/eaDir"))
|
|
|
|
})
|
|
|
|
t.Run("False", func(t *testing.T) {
|
|
|
|
assert.False(t, FileNameHidden("/some/path/folder"))
|
|
|
|
})
|
2023-06-27 19:27:34 +02:00
|
|
|
t.Run("Too short", func(t *testing.T) {
|
|
|
|
assert.False(t, FileNameHidden("a"))
|
|
|
|
})
|
2021-09-24 01:24:36 +02:00
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.False(t, FileNameHidden(""))
|
|
|
|
})
|
|
|
|
}
|