Skip to content

Commit 03b2bab

Browse files
committed
feat: add limit history testcase amount
1 parent a8469bb commit 03b2bab

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewRootCommand() (c *cobra.Command) {
3939
func (o *option) runE(c *cobra.Command, args []string) (err error) {
4040
if o.version {
4141
c.Println(version.GetVersion())
42-
//c.Println(version.GetDate())
42+
c.Println(version.GetDate())
4343
return
4444
}
4545
remoteServer := pkg.NewRemoteServer()

go.mod

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
module github.com/linuxsuren/atest-ext-store-orm
22

3-
go 1.22.2
3+
go 1.22.4
44

5-
toolchain go1.22.4
5+
toolchain go1.22.6
66

77
require (
88
github.com/linuxsuren/api-testing v0.0.18-0.20240712143814-6ce9363d5a07
99
github.com/spf13/cobra v1.8.0
1010
github.com/stretchr/testify v1.9.0
11+
google.golang.org/protobuf v1.33.0
1112
gorm.io/driver/mysql v1.5.2
1213
gorm.io/driver/postgres v1.5.4
1314
gorm.io/driver/sqlite v1.5.6
@@ -53,6 +54,7 @@ require (
5354
github.com/jinzhu/now v1.1.5 // indirect
5455
github.com/josharian/intern v1.0.0 // indirect
5556
github.com/linuxsuren/go-fake-runtime v0.0.4 // indirect
57+
github.com/linuxsuren/oauth-hub v0.0.0-20240809060240-e78c21b5d8d4 // indirect
5658
github.com/linuxsuren/unstructured v0.0.1 // indirect
5759
github.com/mailru/easyjson v0.7.7 // indirect
5860
github.com/mattn/go-sqlite3 v1.14.22 // indirect
@@ -85,15 +87,15 @@ require (
8587
go.uber.org/zap v1.27.0 // indirect
8688
golang.org/x/crypto v0.21.0 // indirect
8789
golang.org/x/net v0.23.0 // indirect
88-
golang.org/x/oauth2 v0.18.0 // indirect
90+
golang.org/x/oauth2 v0.22.0 // indirect
8991
golang.org/x/sync v0.6.0 // indirect
9092
golang.org/x/sys v0.18.0 // indirect
9193
golang.org/x/text v0.14.0 // indirect
92-
google.golang.org/appengine v1.6.8 // indirect
9394
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
9495
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
9596
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
96-
google.golang.org/protobuf v1.33.0 // indirect
9797
gopkg.in/yaml.v2 v2.4.0 // indirect
9898
gopkg.in/yaml.v3 v3.0.1 // indirect
9999
)
100+
101+
replace github.com/linuxsuren/api-testing => github.com/SamYSF/api-testing v0.0.0-20240827074726-d0b782cb43d6

pkg/server.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"gorm.io/gorm"
3131
"gorm.io/gorm/logger"
3232
"log"
33+
"strconv"
3334
"strings"
3435
)
3536

@@ -238,6 +239,22 @@ func (s *dbserver) CreateTestCaseHistory(ctx context.Context, historyTestResult
238239
return
239240
}
240241

242+
store := remote.GetStoreFromContext(ctx)
243+
historyLimit := 10
244+
if v, ok := store.Properties["historyLimit"]; ok {
245+
if parsedHistoryLimit, parseErr := strconv.Atoi(v); parseErr == nil {
246+
historyLimit = parsedHistoryLimit
247+
}
248+
}
249+
250+
var count int64
251+
db.Model(&HistoryTestResult{}).Count(&count)
252+
253+
if count >= int64(historyLimit) {
254+
fmt.Printf("Existing count: %d, limit: %d\nmaximum number of entries reached, cannot create new TestCaseHistory\n", count, historyLimit)
255+
return
256+
}
257+
241258
db.Create(ConvertToDBHistoryTestResult(historyTestResult))
242259
return
243260
}
@@ -380,14 +397,14 @@ func (s *dbserver) Verify(ctx context.Context, in *server.Empty) (reply *server.
380397
return
381398
}
382399

383-
// func (s *dbserver) GetVersion(context.Context, *server.Empty) (ver *server.Version, err error) {
384-
// ver = &server.Version{
385-
// Version: version.GetVersion(),
386-
// Commit: version.GetCommit(),
387-
// Date: version.GetDate(),
388-
// }
389-
// return
390-
// }
400+
func (s *dbserver) GetVersion(context.Context, *server.Empty) (ver *server.Version, err error) {
401+
ver = &server.Version{
402+
Version: version.GetVersion(),
403+
Commit: version.GetCommit(),
404+
Date: version.GetDate(),
405+
}
406+
return
407+
}
391408

392409
func (s *dbserver) PProf(ctx context.Context, in *server.PProfRequest) (data *server.PProfData, err error) {
393410
log.Println("pprof", in.Name)

0 commit comments

Comments
 (0)