Backend: Add tests for pkg
This commit is contained in:
parent
bb30a841c4
commit
b6d9d7e11f
6 changed files with 50 additions and 1 deletions
14
pkg/fs/done_test.go
Normal file
14
pkg/fs/done_test.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestProcessed(t *testing.T) {
|
||||
t.Run("jpeg", func(t *testing.T) {
|
||||
assert.True(t, Processed.Processed())
|
||||
assert.False(t, Found.Processed())
|
||||
})
|
||||
}
|
|
@ -37,3 +37,13 @@ func TestGetMediaType(t *testing.T) {
|
|||
assert.Equal(t, MediaOther, result)
|
||||
})
|
||||
}
|
||||
|
||||
func TestIsMedia(t *testing.T) {
|
||||
t.Run("true", func(t *testing.T) {
|
||||
assert.True(t, IsMedia("testdata/test.jpg"))
|
||||
})
|
||||
|
||||
t.Run("false", func(t *testing.T) {
|
||||
assert.False(t, IsMedia("/IMG_4120.XXX"))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ func TestIsPPID(t *testing.T) {
|
|||
assert.True(t, IsPPID("lt9k3pw1wowuy3c2", 'l'))
|
||||
assert.False(t, IsPPID("lt9k3pw1wowuy3c2123", 'l'))
|
||||
assert.False(t, IsPPID("lt9k3pw1wowuy3c2123", 'l'))
|
||||
assert.False(t, IsPPID("lt9k3pw1AAA-owuy3c2123", 'l'))
|
||||
assert.False(t, IsPPID("", 'l'))
|
||||
assert.False(t, IsPPID("lt9k3pw1w ?owuy 3c2123", 'l'))
|
||||
}
|
||||
|
@ -42,7 +43,6 @@ func TestIsHex(t *testing.T) {
|
|||
assert.False(t, IsHex("550e8400-e29b-11d4-a716_446655440000"))
|
||||
assert.True(t, IsHex("4B1FEF2D1CF4A5BE38B263E0637EDEAD"))
|
||||
assert.False(t, IsHex(""))
|
||||
|
||||
}
|
||||
|
||||
func TestIsUID(t *testing.T) {
|
||||
|
@ -56,3 +56,9 @@ func TestIsUID(t *testing.T) {
|
|||
assert.False(t, IsUID("_", '_'))
|
||||
assert.False(t, IsUID("", '_'))
|
||||
}
|
||||
|
||||
func TestIsLowerAlnum(t *testing.T) {
|
||||
assert.False(t, IsLowerAlnum("dafbfeb8-a129-4e7c-9cf0-e7996a701cdb"))
|
||||
assert.True(t, IsLowerAlnum("dafbe7996a701cdb"))
|
||||
assert.False(t, IsLowerAlnum(""))
|
||||
}
|
||||
|
|
|
@ -36,4 +36,5 @@ func TestSanitizeUUID(t *testing.T) {
|
|||
assert.Equal(t, "", SanitizeUUID("55785BAC-9H4B-4747-B090-EE123FFEE437"))
|
||||
assert.Equal(t, "550e8400-e29b-11d4-a716-446655440000", SanitizeUUID("550e8400-e29b-11d4-a716-446655440000"))
|
||||
assert.Equal(t, "", SanitizeUUID("4B1FEF2D1CF4A5BE38B263E0637EDEAD"))
|
||||
assert.Equal(t, "", SanitizeUUID(""))
|
||||
}
|
||||
|
|
|
@ -17,3 +17,12 @@ func TestClip(t *testing.T) {
|
|||
assert.Equal(t, "", Clip("", -1))
|
||||
})
|
||||
}
|
||||
|
||||
func TestTrimLen(t *testing.T) {
|
||||
t.Run("len < size", func(t *testing.T) {
|
||||
assert.Equal(t, "fox!", TrimLen("fox!", 6))
|
||||
})
|
||||
t.Run("len > size", func(t *testing.T) {
|
||||
assert.Equal(t, "I'm ...", TrimLen("I'm ä lazy BRoWN fox!", 8))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -13,6 +13,11 @@ func TestTime(t *testing.T) {
|
|||
assert.Equal(t, "2018-04-12 19:24:49 +0000 UTC", result.String())
|
||||
})
|
||||
|
||||
t.Run("2018", func(t *testing.T) {
|
||||
result := Time("2018")
|
||||
assert.True(t, result.IsZero())
|
||||
})
|
||||
|
||||
t.Run("2018-04-12 19/24/49.gif", func(t *testing.T) {
|
||||
result := Time("2018-04-12 19/24/49.gif")
|
||||
assert.False(t, result.IsZero())
|
||||
|
@ -221,6 +226,10 @@ func TestIsTime(t *testing.T) {
|
|||
assert.False(t, IsTime("telegram_2020_01_30_09_57_18.jpg"))
|
||||
})
|
||||
|
||||
t.Run("", func(t *testing.T) {
|
||||
assert.False(t, IsTime(""))
|
||||
})
|
||||
|
||||
t.Run("Screenshot 2019_05_21 at 10.45.52.png", func(t *testing.T) {
|
||||
assert.False(t, IsTime("Screenshot 2019_05_21 at 10.45.52.png"))
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue