feat(core): 初始化基础框架并完善接入文档
Verify / verify (push) Canceled after 0s

抽取 Gin、配置、日志、数据库、Redis 与出站 HTTP 基础能力。
新增统一接入指南,将能力清单和相对链接检查纳入 make verify。
对齐远端 module 路径,修正 Redis 读写超时特殊值映射。

验证:make verify、make race-check 均通过。
This commit is contained in:
zhangdeman committed 2026-11-26 19:50:52 -08:00
commit b4c3ac622c
55 files changed
+5862

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
package redis
import (
"context"
"errors"
"path/filepath"
"testing"
"time"
"git.zhangdeman.cn/github/ginframework/fault"
"git.zhangdeman.cn/github/ginframework/internal/testutil/redisserver"
)
func TestOpenNativeClientAndProbeFailure(t *testing.T) {
native := redisserver.New(t, 3)
disableRetries := -1
client, err := Open(context.Background(), Config{Name: "test", Network: "unix", Address: native.Options().Addr, MaxRetries: &disableRetries}, nil)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if err := client.Close(); err != nil {
t.Error(err)
}
})
if err := client.Set(context.Background(), "example", "kept", 0).Err(); err != nil {
t.Fatal(err)
}
if value, err := client.Get(context.Background(), "example").Result(); err != nil || value != "kept" {
t.Fatalf("native result changed: %q %v", value, err)
}
missing, err := Open(context.Background(), Config{Network: "unix", Address: filepath.Join(t.TempDir(), "missing.sock"), MaxRetries: &disableRetries, ProbeTimeoutMS: 50}, nil)
if missing != nil || !fault.Internal(err) {
t.Fatal("failed probe published a client")
}
cancelled, cancel := context.WithCancel(context.Background())
cancel()
missing, err = Open(cancelled, Config{Network: "unix", Address: native.Options().Addr, MaxRetries: &disableRetries}, nil)
if missing != nil || !errors.Is(err, context.Canceled) {
t.Fatal("startup cancellation lost")
}
}
func TestReadWriteTimeoutSentinelsKeepNativeSemantics(t *testing.T) {
native := redisserver.New(t, 3)
for _, test := range []struct {
name string
value int
expected time.Duration
}{
{name: "no timeout", value: -1, expected: 0},
{name: "skip deadline", value: -2, expected: -1},
{name: "milliseconds", value: 120, expected: 120 * time.Millisecond},
} {
t.Run(test.name, func(t *testing.T) {
client, err := Open(context.Background(), Config{
Network: "unix",
Address: native.Options().Addr,
ReadTimeoutMS: &test.value,
WriteTimeoutMS: &test.value,
}, nil)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if err := client.Close(); err != nil {
t.Error(err)
}
})
options := client.Options()
if options.ReadTimeout != test.expected || options.WriteTimeout != test.expected {
t.Fatalf("native timeout semantics lost: read=%v write=%v", options.ReadTimeout, options.WriteTimeout)
}
})
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.