webp_server_go/helper/metadata_test.go
Nova Kwok 43c275e3ec
Adds JPEG XL support, max_height/max_width support (#321)
* WIP JXL

* Fix test

* Tries to fix autobuild

* Tries to fix autobuild

* Add setup go in codeql

* Bump actions version

* Do not print curl output in CI

* Do not print curl output in CI

* Remove Metadata on RAW image

* Update sample config

* better loop

* Prefetch should also respect AllowedType

* Better Export params and UA handle

* Only do conversion on supported formats

* CONVERT_TYPES default to webp only

* CONVERT_TYPES default to webp only

* Add GIF to AllowedTypes

* Update README
2024-03-22 15:12:09 +08:00

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&max_width=&max_height=")
expectedPath := path.Join(config.Config.ImgPath, parsed.Path)
expectedSantizedPath := parsed.Path + "?width=400&height=500&max_width=&max_height="
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)
}
})
}