Files
rustdesk-api/lib/cache/simple_cache_test.go
T
thomasandClaude Opus 4.8 16e97c8efa i18n: Translate all Chinese to English across the codebase
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>
2026-06-27 12:17:04 +02:00

109 lines
1.8 KiB
Go

package cache
import (
"fmt"
"testing"
)
func TestSimpleCache_Set(t *testing.T) {
s := NewSimpleCache()
err := s.Set("key", "value", 0)
if err != nil {
t.Fatalf("write failed")
}
err = s.Set("key", 111, 0)
if err != nil {
t.Fatalf("write failed")
}
}
func TestSimpleCache_Get(t *testing.T) {
s := NewSimpleCache()
err := s.Set("key", "value", 0)
value := ""
err = s.Get("key", &value)
fmt.Println("value", value)
if err != nil {
t.Fatalf("read failed")
}
err = s.Set("key1", 11, 0)
value1 := 0
err = s.Get("key1", &value1)
fmt.Println("value1", value1)
if err != nil {
t.Fatalf("read failed")
}
err = s.Set("key2", []byte{'a', 'b'}, 0)
value2 := []byte{}
err = s.Get("key2", &value2)
fmt.Println("value2", string(value2))
if err != nil {
t.Fatalf("read failed")
}
err = s.Set("key3", 33.33, 0)
var value3 int
err = s.Get("key3", &value3)
fmt.Println("value3", value3)
if err != nil {
t.Fatalf("read failed")
}
}
type r struct {
A string `json:"a"`
B string `json:"b"`
R *rr `json:"r"`
}
type r2 struct {
A string `json:"a"`
B string `json:"b"`
}
type rr struct {
AA string `json:"aa"`
BB string `json:"bb"`
}
func TestSimpleCache_GetStruct(t *testing.T) {
s := NewSimpleCache()
old_rr := &rr{
AA: "aa", BB: "bb",
}
old := &r{
A: "ab", B: "cdc",
R: old_rr,
}
err := s.Set("key", old, 300)
if err != nil {
t.Fatalf("write failed")
}
res := &r{}
err2 := s.Get("key", res)
fmt.Println("res", res)
if err2 != nil {
t.Fatalf("read failed" + err2.Error())
}
// modify the original value to see whether it changes afterward
old.A = "aa"
old_rr.AA = "aaa"
fmt.Println("old", old)
res2 := &r{}
err3 := s.Get("key", res2)
fmt.Println("res2", res2, res2.R.AA, res2.R.BB)
if err3 != nil {
t.Fatalf("read failed" + err3.Error())
}
//if reflect.DeepEqual(res, old) {
// t.Fatalf("read error")
//}
}