webp_server_go/helper/helper_test.go
Benny 13281d929b
add some tests (#239)
* add some tests

* remove template

---------

Co-authored-by: n0vad3v <n0vad3v@riseup.net>
2023-07-03 17:01:13 +08:00

53 lines
1.0 KiB
Go

package helper
import (
"testing"
"webp_server_go/config"
"github.com/stretchr/testify/assert"
)
func TestMain(m *testing.M) {
config.ConfigPath = "../config.json"
config.LoadConfig()
m.Run()
config.ConfigPath = "config.json"
}
func TestFileCount(t *testing.T) {
// test helper dir
count := FileCount("./")
assert.Equal(t, int64(3), count)
}
func TestImageExists(t *testing.T) {
t.Run("file not exists", func(t *testing.T) {
assert.False(t, ImageExists("dgyuaikdsa"))
})
t.Run("file size incorrect", func(t *testing.T) {
assert.False(t, ImageExists("test.txt"))
})
// TODO: how to test lock?
t.Run("test dir", func(t *testing.T) {
assert.False(t, ImageExists("/tmp"))
})
t.Run("test file", func(t *testing.T) {
assert.True(t, ImageExists("./helper_test.go"))
})
}
func TestCheckAllowedType(t *testing.T) {
t.Run("not allowed type", func(t *testing.T) {
assert.False(t, CheckAllowedType("test.txt"))
})
t.Run("allowed type", func(t *testing.T) {
assert.True(t, CheckAllowedType("test.jpg"))
})
}