mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 13:42:02 +08:00
* 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>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
ConfigPath = "../config.json"
|
|
m.Run()
|
|
ConfigPath = "config.json"
|
|
Config.ImgPath = "./pics"
|
|
}
|
|
|
|
func TestLoadConfig(t *testing.T) {
|
|
LoadConfig()
|
|
assert.Equal(t, Config.Host, "127.0.0.1")
|
|
assert.Equal(t, Config.Port, "3333")
|
|
assert.Equal(t, Config.Quality, 80)
|
|
assert.Equal(t, Config.ImgPath, "./pics")
|
|
assert.Equal(t, Config.ImageMap, map[string]string{})
|
|
assert.Equal(t, Config.ExhaustPath, "./exhaust")
|
|
}
|
|
|
|
func TestSwitchProxyMode(t *testing.T) {
|
|
switchProxyMode()
|
|
assert.False(t, ProxyMode)
|
|
Config.ImgPath = "https://picsum.photos"
|
|
switchProxyMode()
|
|
assert.True(t, ProxyMode)
|
|
}
|
|
|
|
func TestParseImgMap(t *testing.T) {
|
|
empty := map[string]string{}
|
|
good := map[string]string{
|
|
"/1": "../pics/dir1",
|
|
"http://example.com": "../pics",
|
|
"https://example.com": "../pics",
|
|
}
|
|
bad := map[string]string{
|
|
"1": "../pics/dir1",
|
|
"httpx://example.com": "../pics",
|
|
"ftp://example.com": "../pics",
|
|
}
|
|
|
|
assert.Equal(t, empty, parseImgMap(empty))
|
|
assert.Equal(t, empty, parseImgMap(bad))
|
|
assert.Equal(t, good, parseImgMap(good))
|
|
|
|
for k, v := range good {
|
|
bad[k] = v
|
|
}
|
|
assert.Equal(t, good, parseImgMap(bad))
|
|
} |