mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 05:32:02 +08:00
* recover middleware * simplify Atoi * metadata data prototype * InterestingAttention * resize itself * Bump version to 0.9.4 Added some comments Removed String() for Extraparams * Add metadata test * Fix CI * Remove unnecessary tests * Update file count * use t.Run to get test case --------- Co-authored-by: n0vad3v <n0vad3v@riseup.net>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package helper
|
|
|
|
import (
|
|
"net/url"
|
|
"path"
|
|
"testing"
|
|
"webp_server_go/config"
|
|
)
|
|
|
|
func TestGetId(t *testing.T) {
|
|
p := "https://example.com/image.jpg?width=200&height=300"
|
|
|
|
t.Run("proxy mode", func(t *testing.T) {
|
|
// Test case 1: Proxy mode
|
|
config.ProxyMode = true
|
|
id, jointPath, santizedPath := getId(p)
|
|
|
|
// Verify the return values
|
|
expectedId := HashString(p)
|
|
expectedPath := ""
|
|
expectedSantizedPath := ""
|
|
if id != expectedId || jointPath != expectedPath || santizedPath != expectedSantizedPath {
|
|
t.Errorf("Test case 1 failed: Expected (%s, %s, %s), but got (%s, %s, %s)",
|
|
expectedId, expectedPath, expectedSantizedPath, id, jointPath, santizedPath)
|
|
}
|
|
})
|
|
t.Run("non-proxy mode", func(t *testing.T) {
|
|
// Test case 2: Non-proxy mode
|
|
config.ProxyMode = false
|
|
p = "/image.jpg?width=400&height=500"
|
|
id, jointPath, santizedPath := getId(p)
|
|
|
|
// Verify the return values
|
|
parsed, _ := url.Parse(p)
|
|
expectedId := HashString(parsed.Path + "?width=400&height=500")
|
|
expectedPath := path.Join(config.Config.ImgPath, parsed.Path)
|
|
expectedSantizedPath := parsed.Path + "?width=400&height=500"
|
|
if id != expectedId || jointPath != expectedPath || santizedPath != expectedSantizedPath {
|
|
t.Errorf("Test case 2 failed: Expected (%s, %s, %s), but got (%s, %s, %s)",
|
|
expectedId, expectedPath, expectedSantizedPath, id, jointPath, santizedPath)
|
|
}
|
|
})
|
|
}
|