Skip to content

Commit

Permalink
fix: convert project_id to string (#4822) (#4830)
Browse files Browse the repository at this point in the history
* feat: convert project_id to string

* feat: ut

Co-authored-by: 悟空 <[email protected]>
  • Loading branch information
erda-bot and dspo committed May 11, 2022
1 parent 0821ee5 commit 0388577
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion modules/core-services/services/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
}
}
10 changes: 10 additions & 0 deletions modules/core-services/services/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 0388577

Please sign in to comment.