mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 21:52:01 +08:00
encoder_test.go
This commit is contained in:
parent
f150285f1c
commit
3d92efaef1
51
encoder_test.go
Normal file
51
encoder_test.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go test -v -cover encoder_test.go encoder.go helper.go
|
||||||
|
func TestWebpEncoder(t *testing.T) {
|
||||||
|
|
||||||
|
var webp = "/tmp/test-result.webp"
|
||||||
|
var target = walker()
|
||||||
|
|
||||||
|
for _, f := range target {
|
||||||
|
//fmt.Println(b, c, webp)
|
||||||
|
runEncoder(t, f, webp)
|
||||||
|
}
|
||||||
|
_ = os.Remove(webp)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func walker() []string {
|
||||||
|
var list []string
|
||||||
|
_ = filepath.Walk("./pics", func(path string, info os.FileInfo, err error) error {
|
||||||
|
if !info.IsDir() {
|
||||||
|
list = append(list, path)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
func runEncoder(t *testing.T, file string, webp string) {
|
||||||
|
var c chan int
|
||||||
|
//t.Logf("Convert from %s to %s", file, webp)
|
||||||
|
var err = WebpEncoder(file, webp, 80, false, c)
|
||||||
|
if file == "pics/empty.jpg" && err != nil {
|
||||||
|
t.Log("Empty file, that's okay.")
|
||||||
|
} else if err != nil {
|
||||||
|
t.Fatalf("Fatal, convert failed for %s: %v ", file, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data, _ := ioutil.ReadFile(webp)
|
||||||
|
types := GetFileContentType(data[:512])
|
||||||
|
if types != "image/webp" {
|
||||||
|
t.Fatal("Fatal, file type is wrong!")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user