From 0388577659755668d9145598c4581f9bfbcaffd1 Mon Sep 17 00:00:00 2001 From: erda-bot <81558540+erda-bot@users.noreply.github.com> Date: Wed, 11 May 2022 09:41:50 +0800 Subject: [PATCH] fix: convert `project_id` to string (#4822) (#4830) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: convert project_id to string * feat: ut Co-authored-by: 悟空 --- modules/core-services/services/project/project.go | 9 ++++++++- modules/core-services/services/project/project_test.go | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/core-services/services/project/project.go b/modules/core-services/services/project/project.go index a98690dc1f6..4feb6aee1a7 100644 --- a/modules/core-services/services/project/project.go +++ b/modules/core-services/services/project/project.go @@ -761,7 +761,7 @@ func (p *Project) fetchPodInfo(dto *apistructs.ProjectDTO) { return } var podInfos []apistructs.PodInfo - if err := p.db.Find(&podInfos, map[string]interface{}{"project_id": dto.ID, "phase": "running"}).Error; err != nil { + if err := p.db.Find(&podInfos, RunningPodCond(dto.ID)).Error; err != nil { logrus.WithError(err).WithField("project_id", dto.ID). Warnln("failed to Find the namespaces info in the project") return @@ -1584,3 +1584,10 @@ func (p *Project) ListUnblockAppCountsByProjectIDS(projectIDS []uint64) ([]model } return p.db.ListUnblockAppCountsByProjectIDS(projectIDS) } + +func RunningPodCond(projectID uint64) map[string]interface{} { + return map[string]interface{}{ + "project_id": strconv.FormatUint(projectID, 10), + "phase": "running", + } +} diff --git a/modules/core-services/services/project/project_test.go b/modules/core-services/services/project/project_test.go index 5ecbe69310b..cd7709f8450 100644 --- a/modules/core-services/services/project/project_test.go +++ b/modules/core-services/services/project/project_test.go @@ -398,3 +398,13 @@ func TestGetNotFoundProject(t *testing.T) { _, err := p.Get(context.Background(), 1, true) assert.Equal(t, dao.ErrNotFoundProject, err) } + +func TestRunningPodCond(t *testing.T) { + cond := RunningPodCond(1) + if cond["project_id"] != "1" { + t.Fatal("error") + } + if cond["phase"] != "running" { + t.Fatal("error") + } +}