Tests: Add unit tests

This commit is contained in:
graciousgrey 2023-06-27 18:41:36 +02:00
parent f53619b004
commit e1ddaa7c0b
4 changed files with 91 additions and 3 deletions

View file

@ -47,3 +47,53 @@ func TestBlacklist_Ok(t *testing.T) {
assert.True(t, list.Allow("raw")) assert.True(t, list.Allow("raw"))
}) })
} }
func TestBlacklist_Contains(t *testing.T) {
t.Run("DNG", func(t *testing.T) {
list := NewBlacklist("dng")
assert.True(t, list.Contains("dng"))
assert.False(t, list.Contains("cr2"))
})
t.Run("Empty", func(t *testing.T) {
list := NewBlacklist("")
assert.False(t, list.Contains(""))
})
}
func TestBlacklist_Set(t *testing.T) {
t.Run("DNG, CR2", func(t *testing.T) {
list := NewBlacklist("dng")
assert.True(t, list.Contains("dng"))
assert.False(t, list.Contains("cr2"))
list.Set("cr2")
assert.True(t, list.Contains("dng"))
assert.True(t, list.Contains("cr2"))
})
t.Run("DNG", func(t *testing.T) {
list := NewBlacklist("dng")
assert.True(t, list.Contains("dng"))
assert.False(t, list.Contains("cr2"))
list.Set("")
assert.True(t, list.Contains("dng"))
assert.False(t, list.Contains("cr2"))
})
}
func TestBlacklist_Add(t *testing.T) {
t.Run("DNG, CR2", func(t *testing.T) {
list := NewBlacklist("dng")
assert.True(t, list.Contains("dng"))
assert.False(t, list.Contains("cr2"))
list.Add("cr2")
assert.True(t, list.Contains("dng"))
assert.True(t, list.Contains("cr2"))
})
t.Run("DNG", func(t *testing.T) {
list := NewBlacklist("dng")
assert.True(t, list.Contains("dng"))
assert.False(t, list.Contains("cr2"))
list.Add("")
assert.True(t, list.Contains("dng"))
assert.False(t, list.Contains("cr2"))
})
}

View file

@ -18,6 +18,22 @@ func TestType_Equal(t *testing.T) {
}) })
} }
func TestType_NotEqual(t *testing.T) {
t.Run("jpg", func(t *testing.T) {
assert.False(t, ImageJPEG.NotEqual("JPG"))
assert.True(t, ImageJPEG.NotEqual("xmp"))
})
}
func TestType_DefaultExt(t *testing.T) {
t.Run("jpg", func(t *testing.T) {
assert.Equal(t, ".jpg", ImageJPEG.DefaultExt())
})
t.Run("avif", func(t *testing.T) {
assert.Equal(t, ".avif", ImageAVIF.DefaultExt())
})
}
func TestToType(t *testing.T) { func TestToType(t *testing.T) {
t.Run("jpg", func(t *testing.T) { t.Run("jpg", func(t *testing.T) {
assert.Equal(t, "jpg", NewType("JPG").String()) assert.Equal(t, "jpg", NewType("JPG").String())

View file

@ -1,6 +1,7 @@
package fs package fs
import ( import (
"github.com/emersion/go-webdav"
"os" "os"
"testing" "testing"
"time" "time"
@ -72,6 +73,19 @@ func TestNewFileInfos(t *testing.T) {
} }
} }
func TestWebFileInfo(t *testing.T) {
infos := webdav.FileInfo{Path: "testdata", Size: 3, ModTime: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), IsDir: true, MIMEType: "image"}
result := WebFileInfo(infos, PathSeparator)
assert.Equal(t, "testdata", result.Name)
assert.Equal(t, "/testdata", result.Abs)
assert.Equal(t, int64(3), result.Size)
assert.Equal(t, "2020-01-01 00:00:00 +0000 UTC", result.Date.String())
assert.Equal(t, true, result.Dir)
}
func TestFileInfos_Less(t *testing.T) { func TestFileInfos_Less(t *testing.T) {
infos := FileInfos{ infos := FileInfos{
{Name: "test.jpg", Abs: "/test.jpg", Size: 10990, Dir: false}, {Name: "test.jpg", Abs: "/test.jpg", Size: 10990, Dir: false},

View file

@ -41,12 +41,20 @@ func TestPathExists(t *testing.T) {
assert.True(t, PathExists("./testdata")) assert.True(t, PathExists("./testdata"))
assert.False(t, PathExists("./testdata/test.jpg")) assert.False(t, PathExists("./testdata/test.jpg"))
assert.False(t, PathExists("./testdata3ggdtgdg")) assert.False(t, PathExists("./testdata3ggdtgdg"))
assert.False(t, PathExists(""))
} }
func TestPathWritable(t *testing.T) { func TestPathWritable(t *testing.T) {
assert.True(t, PathExists("./testdata")) assert.True(t, PathWritable("./testdata"))
assert.False(t, PathExists("./testdata/test.jpg")) assert.False(t, PathWritable("./testdata/test.jpg"))
assert.False(t, PathExists("./testdata3ggdtgdg")) assert.False(t, PathWritable("./testdata3ggdtgdg"))
assert.False(t, PathWritable(""))
}
func TestWritable(t *testing.T) {
assert.True(t, Writable("./testdata"))
assert.False(t, Writable("./testdata3ggdtgdg"))
assert.False(t, Writable(""))
} }
func TestOverwrite(t *testing.T) { func TestOverwrite(t *testing.T) {