code.gitea.io/gitea@v1.22.3/services/actions/rerun_test.go (about) 1 // Copyright 2024 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package actions 5 6 import ( 7 "testing" 8 9 actions_model "code.gitea.io/gitea/models/actions" 10 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestGetAllRerunJobs(t *testing.T) { 15 job1 := &actions_model.ActionRunJob{JobID: "job1"} 16 job2 := &actions_model.ActionRunJob{JobID: "job2", Needs: []string{"job1"}} 17 job3 := &actions_model.ActionRunJob{JobID: "job3", Needs: []string{"job2"}} 18 job4 := &actions_model.ActionRunJob{JobID: "job4", Needs: []string{"job2", "job3"}} 19 20 jobs := []*actions_model.ActionRunJob{job1, job2, job3, job4} 21 22 testCases := []struct { 23 job *actions_model.ActionRunJob 24 rerunJobs []*actions_model.ActionRunJob 25 }{ 26 { 27 job1, 28 []*actions_model.ActionRunJob{job1, job2, job3, job4}, 29 }, 30 { 31 job2, 32 []*actions_model.ActionRunJob{job2, job3, job4}, 33 }, 34 { 35 job3, 36 []*actions_model.ActionRunJob{job3, job4}, 37 }, 38 { 39 job4, 40 []*actions_model.ActionRunJob{job4}, 41 }, 42 } 43 44 for _, tc := range testCases { 45 rerunJobs := GetAllRerunJobs(tc.job, jobs) 46 assert.ElementsMatch(t, tc.rerunJobs, rerunJobs) 47 } 48 }