From 51627d4d406891762ad2e8024acd94571bffae10 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Wed, 6 Jul 2016 12:18:59 +0800 Subject: [PATCH] pass go test --- dao/dao_test.go | 44 +++++++++++++++++++++--------------------- dao/replication_job.go | 4 ++-- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/dao/dao_test.go b/dao/dao_test.go index 5a17986fc..699224700 100644 --- a/dao/dao_test.go +++ b/dao/dao_test.go @@ -1139,24 +1139,40 @@ func TestGetRepPolicyByProject(t *testing.T) { func TestGetRepJobByPolicy(t *testing.T) { jobs, err := GetRepJobByPolicy(999) if err != nil { - log.Errorf("Error occured in GetRepJobByPolicy: %v, policy ID: %d", err, 999) + t.Errorf("Error occured in GetRepJobByPolicy: %v, policy ID: %d", err, 999) return } if len(jobs) > 0 { - log.Errorf("Unexpected length of jobs, expected: 0, in fact: %d", len(jobs)) + t.Errorf("Unexpected length of jobs, expected: 0, in fact: %d", len(jobs)) return } jobs, err = GetRepJobByPolicy(policyID) if err != nil { - log.Errorf("Error occured in GetRepJobByPolicy: %v, policy ID: %d", err, policyID) + t.Errorf("Error occured in GetRepJobByPolicy: %v, policy ID: %d", err, policyID) return } if len(jobs) != 1 { - log.Errorf("Unexpected length of jobs, expected: 1, in fact: %d", len(jobs)) + t.Errorf("Unexpected length of jobs, expected: 1, in fact: %d", len(jobs)) return } if jobs[0].ID != jobID { - log.Errorf("Unexpected job ID in the result, expected: %d, in fact: %d", jobID, jobs[0].ID) + t.Errorf("Unexpected job ID in the result, expected: %d, in fact: %d", jobID, jobs[0].ID) + return + } +} + +func TestFilterRepJobs(t *testing.T) { + jobs, err := FilterRepJobs(policyID, "", "", nil, nil, 1000) + if err != nil { + t.Errorf("Error occured in FilterRepJobs: %v, policy ID: %d", err, policyID) + return + } + if len(jobs) != 1 { + t.Errorf("Unexpected length of jobs, expected: 1, in fact: %d", len(jobs)) + return + } + if jobs[0].ID != jobID { + t.Errorf("Unexpected job ID in the result, expected: %d, in fact: %d", jobID, jobs[0].ID) return } } @@ -1179,22 +1195,6 @@ func TestDeleteRepJob(t *testing.T) { } } -func TestFilterRepJobs(t *testing.T) { - jobs, err := FilterRepJobs(policyID, "", "", nil, nil, 1000) - if err != nil { - log.Errorf("Error occured in FilterRepJobs: %v, policy ID: %d", err, policyID) - return - } - if len(jobs) != 1 { - log.Errorf("Unexpected length of jobs, expected: 1, in fact: %d", len(jobs)) - return - } - if jobs[0].ID != jobID { - log.Errorf("Unexpected job ID in the result, expected: %d, in fact: %d", jobID, jobs[0].ID) - return - } -} - func TestGetRepoJobToStop(t *testing.T) { jobs := [...]models.RepJob{ models.RepJob{ @@ -1265,7 +1265,7 @@ func TestDeleteRepTarget(t *testing.T) { func TestFilterRepPolicies(t *testing.T) { _, err := FilterRepPolicies("name", 0) if err != nil { - t.Fatalf("failed to filter policy") + t.Fatalf("failed to filter policy: %v", err) } } diff --git a/dao/replication_job.go b/dao/replication_job.go index 5c14eb805..adc47391c 100644 --- a/dao/replication_job.go +++ b/dao/replication_job.go @@ -156,7 +156,7 @@ func FilterRepPolicies(name string, projectID int64) ([]*models.RepPolicy, error left join project p on rp.project_id=p.project_id left join replication_target rt on rp.target_id=rt.id left join replication_job rj on rp.id=rj.policy_id and (rj.status="error" - or rj.status="retrying") group by rp.id ` + or rj.status="retrying") ` if len(name) != 0 && projectID != 0 { sql += `where rp.name like ? and rp.project_id = ? ` @@ -170,7 +170,7 @@ func FilterRepPolicies(name string, projectID int64) ([]*models.RepPolicy, error args = append(args, projectID) } - sql += `order by rp.creation_time` + sql += `group by rp.id order by rp.creation_time` var policies []*models.RepPolicy if _, err := o.Raw(sql, args).QueryRows(&policies); err != nil {