You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rerun_test.go 1.1KB

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