Merge pull request #3286 from LinuxSuRen/fix-pip-input-approve-check

Fix the incorrect approvable check of Pipeline input
This commit is contained in:
KubeSphere CI Bot
2021-02-18 10:41:26 +08:00
committed by GitHub
8 changed files with 114 additions and 58 deletions

View File

@@ -1122,14 +1122,10 @@ func (i *Input) GetSubmitters() (submitters []string) {
func (i *Input) Approvable(identify string) (ok bool) {
submitters := i.GetSubmitters()
// it means anyone can approve this if there's no specific one
if len(submitters) == 0 {
ok = true
} else {
for _, submitter := range submitters {
if submitter == identify {
ok = true
}
for _, submitter := range submitters {
if submitter == identify {
ok = true
break
}
}
return

View File

@@ -19,8 +19,8 @@ func TestGetSubmitters(t *testing.T) {
func TestApprovable(t *testing.T) {
input := &Input{}
assert.Equal(t, input.Approvable(""), true, "should allow anyone to approve it if there's no submitter given")
assert.Equal(t, input.Approvable("fake"), true, "should allow anyone to approve it if there's no submitter given")
assert.Equal(t, input.Approvable(""), false, "should allow anyone to approve it if there's no submitter given")
assert.Equal(t, input.Approvable("fake"), false, "should allow anyone to approve it if there's no submitter given")
input.Submitter = "fake"
assert.Equal(t, input.Approvable(""), false, "should not approve by nobody if there's a particular submitter")