mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-08 17:08:17 +01:00
fix golin, add update status
This commit is contained in:
parent
dcbfb4d309
commit
7d7d0c48f4
@ -1709,3 +1709,19 @@ func TestGetScanJobs(t *testing.T) {
|
||||
err = clearTable(ScanJobTable)
|
||||
assert.Nil(err)
|
||||
}
|
||||
|
||||
func TestUpdateScanJobStatus(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
id, err := AddScanJob(sj1)
|
||||
assert.Nil(err)
|
||||
err = UpdateScanJobStatus(id, "newstatus")
|
||||
assert.Nil(err)
|
||||
j, err := GetScanJob(id)
|
||||
assert.Nil(err)
|
||||
assert.Equal("newstatus", j.Status)
|
||||
err = UpdateScanJobStatus(id+9, "newstatus")
|
||||
assert.NotNil(err)
|
||||
err = clearTable(ScanJobTable)
|
||||
assert.Nil(err)
|
||||
|
||||
}
|
||||
|
@ -17,8 +17,12 @@ package dao
|
||||
import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/vmware/harbor/src/common/models"
|
||||
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ScanJobTable is the table name of scan jobs.
|
||||
const ScanJobTable = "img_scan_job"
|
||||
|
||||
// AddScanJob ...
|
||||
@ -52,6 +56,21 @@ func GetScanJobsByDigest(digest string, limit ...int) ([]*models.ScanJob, error)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// UpdateScanJobStatus updates the status of a scan job.
|
||||
func UpdateScanJobStatus(id int64, status string) error {
|
||||
o := GetOrmer()
|
||||
sj := models.ScanJob{
|
||||
ID: id,
|
||||
Status: status,
|
||||
UpdateTime: time.Now(),
|
||||
}
|
||||
n, err := o.Update(&sj, "Status", "UpdateTime")
|
||||
if n == 0 {
|
||||
return fmt.Errorf("Failed to update scan job with id: %d, error: %v", id, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func scanJobQs(limit ...int) orm.QuerySeter {
|
||||
o := GetOrmer()
|
||||
l := -1
|
||||
|
Loading…
Reference in New Issue
Block a user