1
1
mirror of https://github.com/go-gitea/gitea synced 2025-11-01 11:58:25 +00:00

feat: use job emitter

This commit is contained in:
Jason Song
2022-11-04 15:11:51 +08:00
parent cf40dca0c4
commit dc7e64041a
8 changed files with 251 additions and 8 deletions

View File

@@ -0,0 +1,81 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bots
import (
"testing"
bots_model "code.gitea.io/gitea/models/bots"
"github.com/stretchr/testify/assert"
)
func Test_jobStatusResolver_Resolve(t *testing.T) {
tests := []struct {
name string
jobs bots_model.RunJobList
want map[int64]bots_model.Status
}{
{
name: "no blocked",
jobs: bots_model.RunJobList{
{ID: 1, JobID: "1", Status: bots_model.StatusWaiting, Needs: []string{}},
{ID: 2, JobID: "2", Status: bots_model.StatusWaiting, Needs: []string{}},
{ID: 3, JobID: "3", Status: bots_model.StatusWaiting, Needs: []string{}},
},
want: map[int64]bots_model.Status{},
},
{
name: "single blocked",
jobs: bots_model.RunJobList{
{ID: 1, JobID: "1", Status: bots_model.StatusSuccess, Needs: []string{}},
{ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}},
{ID: 3, JobID: "3", Status: bots_model.StatusWaiting, Needs: []string{}},
},
want: map[int64]bots_model.Status{
2: bots_model.StatusWaiting,
},
},
{
name: "multiple blocked",
jobs: bots_model.RunJobList{
{ID: 1, JobID: "1", Status: bots_model.StatusSuccess, Needs: []string{}},
{ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}},
{ID: 3, JobID: "3", Status: bots_model.StatusBlocked, Needs: []string{"1"}},
},
want: map[int64]bots_model.Status{
2: bots_model.StatusWaiting,
3: bots_model.StatusWaiting,
},
},
{
name: "chain blocked",
jobs: bots_model.RunJobList{
{ID: 1, JobID: "1", Status: bots_model.StatusFailure, Needs: []string{}},
{ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}},
{ID: 3, JobID: "3", Status: bots_model.StatusBlocked, Needs: []string{"2"}},
},
want: map[int64]bots_model.Status{
2: bots_model.StatusSkipped,
3: bots_model.StatusSkipped,
},
},
{
name: "loop need",
jobs: bots_model.RunJobList{
{ID: 1, JobID: "1", Status: bots_model.StatusBlocked, Needs: []string{"3"}},
{ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}},
{ID: 3, JobID: "3", Status: bots_model.StatusBlocked, Needs: []string{"2"}},
},
want: map[int64]bots_model.Status{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := newJobStatusResolver(tt.jobs)
assert.Equal(t, tt.want, r.Resolve())
})
}
}