webp_server_go/helper/helper_test.go
BugFest 4003b03022
Multiple backends support (#207)
* Fix: h2non/filetype upgraded to support avif signatures

* Fix: make clean updated to include test/output dirs

* Feature: multi-backend support via IMG_MAP config key as described in #217

* feat: implement both local and remote (proxyMode) mappings for multi-backend

* Feature: multi-backend support via IMG_MAP config key as described in #217

* fix: go-is-svg should be direct import

* fix: imgMap paths are relative to CWD

* feature: IMG_MAP is parsed on start

---------

Co-authored-by: Nova Kwok <n0vad3v@riseup.net>
2023-08-02 23:33:54 +08:00

48 lines
950 B
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(4), count)
}
func TestImageExists(t *testing.T) {
t.Run("file not exists", func(t *testing.T) {
assert.False(t, ImageExists("dgyuaikdsa"))
})
// 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("./helper_test.go"))
})
t.Run("allowed type", func(t *testing.T) {
assert.True(t, CheckAllowedType("test.jpg"))
})
}