2
1
forked from adamm/autogits
Files
autogits/common/reviewers_test.go
Adam Majer 568a2f3df8 PR: Add ability to parse optional reviewers
Document reviewer syntax in the Readme.md
2025-06-10 17:20:33 +02:00

56 lines
1.4 KiB
Go

package common_test
import (
"slices"
"testing"
"src.opensuse.org/autogits/common"
)
func TestReviewers(t *testing.T) {
tests := []struct {
name string
input []string
prj []string
pkg []string
pkg_optional []string
prj_optional []string
}{
{
name: "project and package reviewers",
input: []string{"1", "2", "3", "*5", "+6", "-7"},
prj: []string{"5", "7", common.Bot_BuildReview},
pkg: []string{"1", "2", "3", "5", "6"},
},
{
name: "optional project and package reviewers",
input: []string{"~1", "2", "3", "~*5", "+6", "-7"},
prj: []string{"7", common.Bot_BuildReview},
pkg: []string{"2", "3", "6"},
prj_optional: []string{"5"},
pkg_optional: []string{"1", "5"},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
reviewers := common.ParseReviewers(test.input)
if !slices.Equal(reviewers.Prj, test.prj) {
t.Error("unexpected return of ForProject():", reviewers.Prj)
}
if !slices.Equal(reviewers.Pkg, test.pkg) {
t.Error("unexpected return of ForPackage():", reviewers.Pkg)
}
if !slices.Equal(reviewers.PrjOptional, test.prj_optional) {
t.Error("unexpected return of ForProjectOptional():", reviewers.Prj)
}
if !slices.Equal(reviewers.PkgOptional, test.pkg_optional) {
t.Error("unexpected return of ForPackageOptional():", reviewers.Pkg)
}
})
}
}