Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

升级 Ginx 版本 #318

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/bwmarrin/snowflake v0.3.0
github.com/ecodeclub/ecache v0.0.0-20240111145855-75679834beca
github.com/ecodeclub/ekit v0.0.9-0.20240331142359-871f65136a9b
github.com/ecodeclub/ginx v0.0.0-20250123094857-7acefcc057ee
github.com/ecodeclub/ginx v0.0.1
github.com/ecodeclub/mq-api v0.0.0-20240508035004-fd7de3346cfe
github.com/ego-component/egorm v1.1.1
github.com/gin-contrib/cors v1.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ github.com/ecodeclub/ecache v0.0.0-20240111145855-75679834beca h1:qksXJxULYYX+3Z
github.com/ecodeclub/ecache v0.0.0-20240111145855-75679834beca/go.mod h1:faDaVWB0J1EfgyY6e7Z40EWv65Asu4FrtlWVDAOBRiM=
github.com/ecodeclub/ekit v0.0.9-0.20240331142359-871f65136a9b h1:E2+ixsdn65iQdIBWEC0afanMV0P9/vcaTUq9aLWOTzk=
github.com/ecodeclub/ekit v0.0.9-0.20240331142359-871f65136a9b/go.mod h1:rEGubThvxoIQT/qnbVBkZgSvYwgKrY/dtwEWKRTmgeY=
github.com/ecodeclub/ginx v0.0.0-20250123094857-7acefcc057ee h1:lEwj76B8kDnAFKKfC2kIF+uaG2vu83s1hVxyuZbmytU=
github.com/ecodeclub/ginx v0.0.0-20250123094857-7acefcc057ee/go.mod h1:PCGcpNNuknwamOKIEkRwfwKngqg4syGydrONSIxb08w=
github.com/ecodeclub/ginx v0.0.1 h1:YLGf3gCibcAzuyfnR4nvimd59YVOwb2NyJoSbELa4/Q=
github.com/ecodeclub/ginx v0.0.1/go.mod h1:PCGcpNNuknwamOKIEkRwfwKngqg4syGydrONSIxb08w=
github.com/ecodeclub/mq-api v0.0.0-20240508035004-fd7de3346cfe h1:PJ/YcqAQx/9XnRDoLGD9Or1gNgYjJK72+RhX7TbyMao=
github.com/ecodeclub/mq-api v0.0.0-20240508035004-fd7de3346cfe/go.mod h1:M+2owQhSRoGyX15L0rUdoSvUDvTOuexquG/605wqYtI=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
Expand Down
138 changes: 136 additions & 2 deletions internal/cases/internal/integration/admin_case_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,37 @@ func (s *AdminCaseHandlerTestSuite) TestPublish() {
publishCase, err := s.dao.GetPublishCase(ctx, 1)
require.NoError(t, err)
s.assertCase(t, wantCase, dao.Case(publishCase))
s.cacheAssertCase(domain.Case{
Id: 1,
Uid: uid,
Title: "案例1",
Content: "案例1内容",
Introduction: "案例1介绍",
Labels: []string{
"MySQL",
},
Status: domain.PublishedStatus,
GithubRepo: "www.github.com",
GiteeRepo: "www.gitee.com",
Keywords: "mysql_keywords",
Shorthand: "mysql_shorthand",
Highlight: "mysql_highlight",
Guidance: "mysql_guidance",
Biz: "case",
BizId: 11,
})
s.cacheAssertCaseList("case", []domain.Case{
{
Id: 1,
Title: "案例1",
Introduction: "案例1介绍",
Labels: []string{
"MySQL",
},
Status: domain.PublishedStatus,
},
})

},
req: web.SaveReq{
Case: web.Case{
Expand Down Expand Up @@ -524,12 +555,26 @@ func (s *AdminCaseHandlerTestSuite) TestPublish() {
Shorthand: "old_mysql_shorthand",
Highlight: "old_mysql_highlight",
Guidance: "old_mysql_guidance",
Biz: "case",
Biz: "question",
BizId: 11,
Ctime: 123,
Utime: 234,
}).Error
require.NoError(t, err)
cs := []domain.Case{
{
Id: 2,
Title: "老的案例标题",
Content: "老的案例内容",
Introduction: "老的案例介绍",
Labels: []string{"old-MySQL"},
Status: domain.PublishedStatus,
},
}
csByte, err := json.Marshal(cs)
require.NoError(t, err)
err = s.rdb.Set(ctx, "cases:list:question", string(csByte), 24*time.Hour)
require.NoError(t, err)
},
after: func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
Expand Down Expand Up @@ -560,6 +605,36 @@ func (s *AdminCaseHandlerTestSuite) TestPublish() {
require.NoError(t, err)
publishCase.Ctime = 123
s.assertCase(t, wantCase, dao.Case(publishCase))
s.cacheAssertCase(domain.Case{
Id: 2,
Uid: uid,
Title: "案例2",
Content: "案例2内容",
Introduction: "案例2介绍",
Labels: []string{
"MySQL",
},
Status: domain.PublishedStatus,
GithubRepo: "www.github.com",
GiteeRepo: "www.gitee.com",
Keywords: "mysql_keywords",
Shorthand: "mysql_shorthand",
Highlight: "mysql_highlight",
Guidance: "mysql_guidance",
Biz: "question",
BizId: 12,
})
s.cacheAssertCaseList("question", []domain.Case{
{
Id: 2,
Title: "案例2",
Introduction: "案例2介绍",
Labels: []string{
"MySQL",
},
Status: domain.PublishedStatus,
},
})
},
req: web.SaveReq{
Case: web.Case{
Expand Down Expand Up @@ -621,6 +696,7 @@ func (s *AdminCaseHandlerTestSuite) TestPublish() {
pubCase := dao.PublishCase(oldCase)
err = s.db.WithContext(ctx).Create(pubCase).Error
require.NoError(t, err)

},
after: func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
Expand Down Expand Up @@ -651,6 +727,23 @@ func (s *AdminCaseHandlerTestSuite) TestPublish() {
require.NoError(t, err)
publishCase.Ctime = 123
s.assertCase(t, wantCase, dao.Case(publishCase))
s.cacheAssertCase(domain.Case{
Id: 3,
Uid: uid,
Title: "案例2",
Content: "案例2内容",
Introduction: "案例2介绍",
Labels: []string{"MySQL"},
Status: domain.PublishedStatus,
GithubRepo: "www.github.com",
GiteeRepo: "www.gitee.com",
Keywords: "mysql_keywords",
Shorthand: "mysql_shorthand",
Highlight: "mysql_highlight",
Guidance: "mysql_guidance",
Biz: "ai",
BizId: 13,
})
},
req: web.SaveReq{
Case: web.Case{
Expand Down Expand Up @@ -696,6 +789,24 @@ func (s *AdminCaseHandlerTestSuite) TestPublish() {
}
}

func (s *AdminCaseHandlerTestSuite) cacheAssertCase(ca domain.Case) {
t := s.T()
key := fmt.Sprintf("cases:publish:%d", ca.Id)
val := s.rdb.Get(context.Background(), key)
require.NoError(t, val.Err)
valStr, err := val.String()
require.NoError(t, err)
actualCa := domain.Case{}
json.Unmarshal([]byte(valStr), &actualCa)
require.True(t, actualCa.Ctime.Unix() > 0)
require.True(t, actualCa.Utime.Unix() > 0)
ca.Ctime = actualCa.Ctime
ca.Utime = actualCa.Utime
assert.Equal(t, ca, actualCa)
_, err = s.rdb.Delete(context.Background(), key)
require.NoError(t, err)
}

func (s *AdminCaseHandlerTestSuite) TestEvent() {
t := s.T()
var evt event.Case
Expand Down Expand Up @@ -733,7 +844,7 @@ func (s *AdminCaseHandlerTestSuite) TestEvent() {
Highlight: "mysql_highlight",
Guidance: "mysql_guidance",
Status: 2,
Biz: domain.DefaultBiz,
Biz: "bbb",
Ctime: time.UnixMilli(123),
Utime: time.UnixMilli(123),
}, ca)
Expand All @@ -751,6 +862,7 @@ func (s *AdminCaseHandlerTestSuite) TestEvent() {
Shorthand: "mysql_shorthand",
Highlight: "mysql_highlight",
Guidance: "mysql_guidance",
Biz: "bbb",
},
}
req2, err := http.NewRequest(http.MethodPost,
Expand Down Expand Up @@ -797,3 +909,25 @@ func (s *AdminCaseHandlerTestSuite) assertCase(t *testing.T, expect dao.Case, ca
func TestAdminCaseHandler(t *testing.T) {
suite.Run(t, new(AdminCaseHandlerTestSuite))
}

func (s *AdminCaseHandlerTestSuite) cacheAssertCaseList(biz string, cases []domain.Case) {
key := fmt.Sprintf("cases:list:%s", biz)
val := s.rdb.Get(context.Background(), key)
require.NoError(s.T(), val.Err)

var cs []domain.Case
err := json.Unmarshal([]byte(val.Val.(string)), &cs)
require.NoError(s.T(), err)
require.Equal(s.T(), len(cases), len(cs))
for idx, q := range cs {
require.True(s.T(), q.Utime.UnixMilli() > 0)
require.True(s.T(), q.Id > 0)
cs[idx].Id = cases[idx].Id
cs[idx].Utime = cases[idx].Utime
cs[idx].Ctime = cases[idx].Ctime

}
assert.Equal(s.T(), cases, cs)
_, err = s.rdb.Delete(context.Background(), key)
require.NoError(s.T(), err)
}
Loading
Loading