Skip to content

Commit

Permalink
fix: lint and ut
Browse files Browse the repository at this point in the history
Signed-off-by: xu.zhu <[email protected]>
  • Loading branch information
xuzhu-591 committed Sep 25, 2023
1 parent 3bac5fa commit 0946096
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions core/controller/application/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,9 @@ func (c *controller) recordMemberCreatedEvent(ctx context.Context, applicationID
},
})
}
if _, err := c.eventMgr.CreateEvent(ctx, events...); err != nil {
log.Warningf(ctx, "failed to create event, err: %s", err.Error())
if len(events) > 0 {
if _, err := c.eventMgr.CreateEvent(ctx, events...); err != nil {
log.Warningf(ctx, "failed to create event, err: %s", err.Error())
}
}
}
6 changes: 6 additions & 0 deletions core/controller/application/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
tmodels "github.com/horizoncd/horizon/pkg/template/models"
trmodels "github.com/horizoncd/horizon/pkg/templaterelease/models"
trschema "github.com/horizoncd/horizon/pkg/templaterelease/schema"
usermodel "github.com/horizoncd/horizon/pkg/user/models"
userservice "github.com/horizoncd/horizon/pkg/user/service"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -293,6 +294,9 @@ func TestMain(m *testing.M) {
if err := db.AutoMigrate(&eventmodels.Event{}); err != nil {
panic(err)
}
if err := db.AutoMigrate(&usermodel.User{}); err != nil {
panic(err)
}
ctx = context.TODO()
ctx = context.WithValue(ctx, common.UserContextKey(), &userauth.DefaultInfo{
Name: "Tony",
Expand Down Expand Up @@ -363,6 +367,7 @@ func Test(t *testing.T) {
clusterMgr: manager.ClusterMgr,
userSvc: userservice.NewService(manager),
eventMgr: manager.EventMgr,
memberManager: manager.MemberMgr,
}

group, err := manager.GroupMgr.Create(ctx, &groupmodels.Group{
Expand Down Expand Up @@ -518,6 +523,7 @@ func TestV2(t *testing.T) {
clusterMgr: manager.ClusterMgr,
userSvc: userservice.NewService(manager),
eventMgr: manager.EventMgr,
memberManager: manager.MemberMgr,
}

group, err := manager.GroupMgr.Create(ctx, &groupmodels.Group{
Expand Down
6 changes: 4 additions & 2 deletions core/controller/cluster/controller_basic_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,10 @@ func (c *controller) recordMemberCreatedEvent(ctx context.Context, clusterID uin
},
})
}
if _, err := c.eventMgr.CreateEvent(ctx, events...); err != nil {
log.Warningf(ctx, "failed to create event, err: %s", err.Error())
if len(events) > 0 {
if _, err := c.eventMgr.CreateEvent(ctx, events...); err != nil {
log.Warningf(ctx, "failed to create event, err: %s", err.Error())
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions core/controller/cluster/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ func test(t *testing.T) {
tagMgr: tagManager,
applicationGitRepo: applicationGitRepo,
eventMgr: manager.EventMgr,
memberManager: manager.MemberMgr,
tokenSvc: tokenservice.NewService(manager, tokenconfig.Config{
JwtSigningKey: "horizon",
CallbackTokenExpireIn: time.Hour * 2,
Expand Down Expand Up @@ -1421,6 +1422,7 @@ func testV2(t *testing.T) {
registryFty: registryFty,
cd: mockCd,
eventMgr: manager.EventMgr,
memberManager: manager.MemberMgr,
}
applicationGitRepo.EXPECT().GetApplication(gomock.Any(), applicationName, gomock.Any()).
Return(&appgitrepo.GetResponse{
Expand Down Expand Up @@ -1647,6 +1649,7 @@ func testUpgrade(t *testing.T) {
cd: mockCd,
eventMgr: manager.EventMgr,
templateUpgradeMapper: templateUpgradeMapper,
memberManager: manager.MemberMgr,
}

applicationGitRepo.EXPECT().GetApplication(ctx, gomock.Any(), gomock.Any()).
Expand Down

0 comments on commit 0946096

Please sign in to comment.