Translate Chinese comments, log/error messages, validator labels and Swagger annotations to English throughout the source code, generated Swagger docs, config files and CI workflows. Make the English README primary: README.md now holds the English docs and README_EN.md holds the Chinese version, with cross-language links updated accordingly. Note: the generated docs/ swagger files were translated in place; run `go generate ./...` (swag init) to regenerate them from the now-English annotations when a Go toolchain is available. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
95 lines
1.6 KiB
Go
95 lines
1.6 KiB
Go
package cache
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestFileSet(t *testing.T) {
|
|
fc := NewFileCache()
|
|
err := fc.Set("123", "ddd", 0)
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
t.Fatalf("write failed")
|
|
}
|
|
}
|
|
|
|
func TestFileGet(t *testing.T) {
|
|
fc := NewFileCache()
|
|
res := ""
|
|
err := fc.Get("123", &res)
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
t.Fatalf("read failed")
|
|
}
|
|
fmt.Println("res", res)
|
|
}
|
|
func TestFileSetGet(t *testing.T) {
|
|
fc := NewFileCache()
|
|
err := fc.Set("key1", "ddd", 0)
|
|
res := ""
|
|
err = fc.Get("key1", &res)
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
t.Fatalf("read failed")
|
|
}
|
|
fmt.Println("res", res)
|
|
}
|
|
func TestFileGetJson(t *testing.T) {
|
|
fc := NewFileCache()
|
|
old := &r{
|
|
A: "a", B: "b",
|
|
}
|
|
fc.Set("123", old, 0)
|
|
res := &r{}
|
|
err2 := fc.Get("123", res)
|
|
fmt.Println("res", res)
|
|
if err2 != nil {
|
|
t.Fatalf("read failed" + err2.Error())
|
|
}
|
|
}
|
|
func TestFileSetGetJson(t *testing.T) {
|
|
fc := NewFileCache()
|
|
|
|
old_rr := &rr{AA: "aa", BB: "bb"}
|
|
old := &r{
|
|
A: "a", B: "b",
|
|
R: old_rr,
|
|
}
|
|
err := fc.Set("123", old, 300)
|
|
if err != nil {
|
|
t.Fatalf("write failed")
|
|
}
|
|
//old_rr.AA = "aaa"
|
|
fmt.Println("old_rr", old)
|
|
|
|
res := &r{}
|
|
err2 := fc.Get("123", res)
|
|
fmt.Println("res", res)
|
|
if err2 != nil {
|
|
t.Fatalf("read failed" + err2.Error())
|
|
}
|
|
if !reflect.DeepEqual(res, old) {
|
|
t.Fatalf("read error")
|
|
}
|
|
|
|
}
|
|
|
|
func BenchmarkSet(b *testing.B) {
|
|
fc := NewFileCache()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
fc.Set("123", "{dsv}", 1000)
|
|
}
|
|
}
|
|
|
|
func BenchmarkGet(b *testing.B) {
|
|
fc := NewFileCache()
|
|
b.ResetTimer()
|
|
v := ""
|
|
for i := 0; i < b.N; i++ {
|
|
fc.Get("123", &v)
|
|
}
|
|
}
|