重构:完成架构一致性整改与生命周期收口
This commit is contained in:
1 parent
55904cc409
commit
9eb6be2875
344 files changed
+15961
-13926
No files matched your search
@@ -12,47 +12,47 @@ import (
|
||||
"xianyu-go/internal/xianyu/mtop"
|
||||
)
|
||||
|
||||
// stubProfileMTop 保存stubProfileMTop,供当前处理流程使用
|
||||
// stubProfileMTop 用于本次流程后续判断的stubProfileMTop
|
||||
type stubProfileMTop struct {
|
||||
mtop.Client
|
||||
profile func(context.Context, string) (*mtop.UserProfileResult, error)
|
||||
}
|
||||
|
||||
// FetchUserProfile 负责Fetch用户Profile相关处理。
|
||||
// FetchUserProfile 封装Fetch用户Profile业务协调。
|
||||
func (s *stubProfileMTop) FetchUserProfile(ctx context.Context, cookies string) (*mtop.UserProfileResult, error) {
|
||||
return s.profile(ctx, cookies)
|
||||
}
|
||||
|
||||
// TestRefreshAccountProfilePersistsCookieSessionOnResponseError 负责TestRefresh账号ProfilePersists登录凭证会话On响应错误相关处理。
|
||||
// TestRefreshAccountProfilePersistsCookieSessionOnResponseError 封装TestRefresh账号ProfilePersists登录凭证会话On响应错误业务协调。
|
||||
func TestRefreshAccountProfilePersistsCookieSessionOnResponseError(t *testing.T) {
|
||||
// srv、store、cleanup 保存srv、store、cleanup,供当前处理流程使用
|
||||
// srv、store、cleanup 用于本次流程后续判断的srv、store、cleanup
|
||||
srv, store, cleanup := newTestServer(t)
|
||||
defer cleanup()
|
||||
|
||||
// ctx 保存ctx,供当前处理流程使用
|
||||
// ctx 用于本次流程后续判断的ctx
|
||||
ctx := context.Background()
|
||||
// detail、err 保存detail、err,供当前处理流程使用
|
||||
// detail、err 用于本次流程后续判断的detail、err
|
||||
detail, err := store.Cookies.GetDetails(ctx, "acc1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// snapshot 保存snapshot,供当前处理流程使用
|
||||
// snapshot 用于本次流程后续判断的snapshot
|
||||
snapshot := []cookierefresh.BrowserCookie{
|
||||
{Name: "unb", Value: "123", Domain: ".goofish.com", Path: "/", Secure: true},
|
||||
{Name: "_m_h5_tk", Value: "tk1_1", Domain: ".goofish.com", Path: "/", Secure: true},
|
||||
{Name: "keep", Value: "yes", Domain: "www.goofish.com", Path: "/im", Secure: true},
|
||||
}
|
||||
// metadata 保存metadata,供当前处理流程使用
|
||||
// metadata 用于本次流程后续判断的metadata
|
||||
metadata := cookierefresh.MetadataWithSnapshot(detail.MetadataJSON, snapshot)
|
||||
if // err 保存err,供当前处理流程使用
|
||||
if // err 用于本次流程后续判断的err
|
||||
err := store.Cookies.UpdateRenewalCookie(ctx, detail.ID, detail.Value, metadata, time.Now().Unix()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// client 保存client,供当前处理流程使用
|
||||
// client 用于本次流程后续判断的client
|
||||
client := mtop.NewClient()
|
||||
client.HTTPClient = &http.Client{Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
|
||||
// header 保存header,供当前处理流程使用
|
||||
// header 用于本次流程后续判断的header
|
||||
header := make(http.Header)
|
||||
header.Add("Set-Cookie", "rotated=fresh; Domain=.goofish.com; Path=/; Secure; HttpOnly")
|
||||
return &http.Response{
|
||||
@@ -79,7 +79,7 @@ func TestRefreshAccountProfilePersistsCookieSessionOnResponseError(t *testing.T)
|
||||
t.Fatal("无效响应应返回解析错误")
|
||||
}
|
||||
|
||||
// updated、err 保存updated、err,供当前处理流程使用
|
||||
// updated、err 用于本次流程后续判断的updated、err
|
||||
updated, err := store.Cookies.GetDetails(ctx, "acc1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -87,12 +87,12 @@ func TestRefreshAccountProfilePersistsCookieSessionOnResponseError(t *testing.T)
|
||||
if !strings.Contains(updated.Value, "rotated=fresh") {
|
||||
t.Fatalf("响应错误时仍应保存 canonical Cookie: %q", updated.Value)
|
||||
}
|
||||
// updatedSnapshot、ok 保存updatedSnapshot、ok,供当前处理流程使用
|
||||
// updatedSnapshot、ok 用于本次流程后续判断的updatedSnapshot、ok
|
||||
updatedSnapshot, ok := cookierefresh.SnapshotFromMetadataOK(updated.MetadataJSON)
|
||||
if !ok {
|
||||
t.Fatal("响应错误时不应清除权威 Cookie Jar")
|
||||
}
|
||||
// values 保存values,供当前处理流程使用
|
||||
// values 用于本次流程后续判断的values
|
||||
values := make(map[string]string, len(updatedSnapshot))
|
||||
// cookie 表示当前遍历过程中的登录凭证
|
||||
for _, cookie := range updatedSnapshot {
|
||||
@@ -103,9 +103,9 @@ func TestRefreshAccountProfilePersistsCookieSessionOnResponseError(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRefreshAccountProfileKeepsAuthoritativeSnapshotWithFlatMock 负责TestRefresh账号ProfileKeepsAuthoritativeSnapshotWithFlatMock相关处理。
|
||||
// TestRefreshAccountProfileKeepsAuthoritativeSnapshotWithFlatMock 封装TestRefresh账号ProfileKeepsAuthoritativeSnapshotWithFlatMock业务协调。
|
||||
func TestRefreshAccountProfileKeepsAuthoritativeSnapshotWithFlatMock(t *testing.T) {
|
||||
// srv、store、cleanup 保存srv、store、cleanup,供当前处理流程使用
|
||||
// srv、store、cleanup 用于本次流程后续判断的srv、store、cleanup
|
||||
srv, store, cleanup := newTestServer(t)
|
||||
defer cleanup()
|
||||
seedStaleCookieSnapshot(t, store, "acc1")
|
||||
@@ -116,14 +116,14 @@ func TestRefreshAccountProfileKeepsAuthoritativeSnapshotWithFlatMock(t *testing.
|
||||
UpdatedCookies: "unb=123; _m_h5_tk=mockfresh_2",
|
||||
}, nil
|
||||
}}
|
||||
// detail、err 保存detail、err,供当前处理流程使用
|
||||
// detail、err 用于本次流程后续判断的detail、err
|
||||
detail, err := store.Cookies.GetDetails(context.Background(), "acc1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _ = srv.accountProfileApplication().RefreshProfile(context.Background(), detail.UserID, detail.ID)
|
||||
|
||||
// updated、err 保存updated、err,供当前处理流程使用
|
||||
// updated、err 用于本次流程后续判断的updated、err
|
||||
updated, err := store.Cookies.GetDetails(context.Background(), "acc1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -131,15 +131,15 @@ func TestRefreshAccountProfileKeepsAuthoritativeSnapshotWithFlatMock(t *testing.
|
||||
if strings.Contains(updated.Value, "_m_h5_tk=mockfresh_2") {
|
||||
t.Fatalf("完整 Jar 不得被 mock 扁平 Cookie 覆盖: %q", updated.Value)
|
||||
}
|
||||
if // complete 保存complete,供当前处理流程使用
|
||||
if // complete 用于本次流程后续判断的complete
|
||||
_, complete := cookierefresh.SnapshotFromMetadataOK(updated.MetadataJSON); !complete {
|
||||
t.Fatalf("完整 Jar 未发生变化时不得清除: %s", updated.MetadataJSON)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRefreshAccountProfileKeepsFlatMockFallbackWithoutSnapshot 负责TestRefresh账号ProfileKeepsFlatMockFallbackWithoutSnapshot相关处理。
|
||||
// TestRefreshAccountProfileKeepsFlatMockFallbackWithoutSnapshot 封装TestRefresh账号ProfileKeepsFlatMockFallbackWithoutSnapshot业务协调。
|
||||
func TestRefreshAccountProfileKeepsFlatMockFallbackWithoutSnapshot(t *testing.T) {
|
||||
// srv、store、cleanup 保存srv、store、cleanup,供当前处理流程使用
|
||||
// srv、store、cleanup 用于本次流程后续判断的srv、store、cleanup
|
||||
srv, store, cleanup := newTestServer(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -149,14 +149,14 @@ func TestRefreshAccountProfileKeepsFlatMockFallbackWithoutSnapshot(t *testing.T)
|
||||
UpdatedCookies: "unb=123; _m_h5_tk=mockfresh_2",
|
||||
}, nil
|
||||
}}
|
||||
// detail、err 保存detail、err,供当前处理流程使用
|
||||
// detail、err 用于本次流程后续判断的detail、err
|
||||
detail, err := store.Cookies.GetDetails(context.Background(), "acc1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _ = srv.accountProfileApplication().RefreshProfile(context.Background(), detail.UserID, detail.ID)
|
||||
|
||||
// updated、err 保存updated、err,供当前处理流程使用
|
||||
// updated、err 用于本次流程后续判断的updated、err
|
||||
updated, err := store.Cookies.GetDetails(context.Background(), "acc1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in new issue
Block a user