maintner: skip incomplete CLs in ForeachOpenCL

CL 107296 has created a GerritCL.complete method and started
using it to enforce non-nil Meta and Commit fields in GerritCL
that are returned to the client.

It was used in ForeachCLUnsorted to skip incomplete CLs when
iterating over the gp.cls map, but due to an oversight, it
was not added to ForeachOpenCL. As a result, it was possible
for incomplete CLs to be iterated over via ForeachOpenCL.
This change fixes that by adding the missing complete check.

Update TestGerritMetaNonNil test to check ForeachOpenCL too.

Add missing period at the end of a sentence in ForeachCLUnsorted
documentation.

Fixes golang/go#27536.

Change-Id: I453d0f2b2b2793ed1b8a55bae1c2254906d74792
Reviewed-on: https://go-review.googlesource.com/135677
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Dmitri Shuralyov 2018-09-17 16:00:16 -04:00
Родитель 1d8c3548c0
Коммит 0eda5f7a6a
2 изменённых файлов: 20 добавлений и 5 удалений

Просмотреть файл

@ -179,7 +179,7 @@ func (gp *GerritProject) ForeachNonChangeRef(fn func(ref string, hash GitHash) e
func (gp *GerritProject) ForeachOpenCL(fn func(*GerritCL) error) error {
var s []*GerritCL
for _, cl := range gp.cls {
if cl.Status != "new" || cl.Private {
if !cl.complete() || cl.Status != "new" || cl.Private {
continue
}
s = append(s, cl)
@ -193,7 +193,7 @@ func (gp *GerritProject) ForeachOpenCL(fn func(*GerritCL) error) error {
return nil
}
// ForeachCLUnsorted calls fn for each CL in the repo, in any order
// ForeachCLUnsorted calls fn for each CL in the repo, in any order.
//
// If fn returns an error, iteration ends and ForeachCLUnsorted returns with
// that error.

Просмотреть файл

@ -108,19 +108,34 @@ func TestGerritMetaNonNil(t *testing.T) {
var maxCL int32
gp.ForeachCLUnsorted(func(cl *maintner.GerritCL) error {
if cl.Meta == nil {
t.Errorf("%s: enumerated CL %d has nil Meta", gp.ServerSlashProject(), cl.Number)
t.Errorf("%s: ForeachCLUnsorted-enumerated CL %d has nil Meta", gp.ServerSlashProject(), cl.Number)
}
if len(cl.Metas) == 0 {
t.Errorf("%s: enumerated CL %d has empty Metas", gp.ServerSlashProject(), cl.Number)
t.Errorf("%s: ForeachCLUnsorted-enumerated CL %d has empty Metas", gp.ServerSlashProject(), cl.Number)
}
if cl.Commit == nil {
t.Errorf("%s: enumerated CL %d has nil Commit", gp.ServerSlashProject(), cl.Number)
t.Errorf("%s: ForeachCLUnsorted-enumerated CL %d has nil Commit", gp.ServerSlashProject(), cl.Number)
}
if cl.Number > maxCL {
maxCL = cl.Number
}
return nil
})
gp.ForeachOpenCL(func(cl *maintner.GerritCL) error {
if cl.Meta == nil {
t.Errorf("%s: ForeachOpenCL-enumerated CL %d has nil Meta", gp.ServerSlashProject(), cl.Number)
}
if len(cl.Metas) == 0 {
t.Errorf("%s: ForeachOpenCL-enumerated CL %d has empty Metas", gp.ServerSlashProject(), cl.Number)
}
if cl.Commit == nil {
t.Errorf("%s: ForeachOpenCL-enumerated CL %d has nil Commit", gp.ServerSlashProject(), cl.Number)
}
if cl.Number > maxCL {
t.Fatalf("%s: ForeachOpenCL-enumerated CL %d higher than max CL %d from ForeachCLUnsorted", gp.ServerSlashProject(), cl.Number, maxCL)
}
return nil
})
// And test that CL won't yield an incomplete one either:
for n := int32(0); n <= maxCL; n++ {