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.

task_state_test.go 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2022 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 TestFullSteps(t *testing.T) {
  10. tests := []struct {
  11. name string
  12. task *actions_model.ActionTask
  13. want []*actions_model.ActionTaskStep
  14. }{
  15. {
  16. name: "regular",
  17. task: &actions_model.ActionTask{
  18. Steps: []*actions_model.ActionTaskStep{
  19. {Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
  20. },
  21. Status: actions_model.StatusSuccess,
  22. Started: 10000,
  23. Stopped: 10100,
  24. LogLength: 100,
  25. },
  26. want: []*actions_model.ActionTaskStep{
  27. {Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
  28. {Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
  29. {Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
  30. },
  31. },
  32. {
  33. name: "failed step",
  34. task: &actions_model.ActionTask{
  35. Steps: []*actions_model.ActionTaskStep{
  36. {Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
  37. {Status: actions_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
  38. {Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
  39. },
  40. Status: actions_model.StatusFailure,
  41. Started: 10000,
  42. Stopped: 10100,
  43. LogLength: 100,
  44. },
  45. want: []*actions_model.ActionTaskStep{
  46. {Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
  47. {Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
  48. {Status: actions_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
  49. {Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
  50. {Name: postStepName, Status: actions_model.StatusFailure, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
  51. },
  52. },
  53. {
  54. name: "first step is running",
  55. task: &actions_model.ActionTask{
  56. Steps: []*actions_model.ActionTaskStep{
  57. {Status: actions_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
  58. },
  59. Status: actions_model.StatusRunning,
  60. Started: 10000,
  61. Stopped: 10100,
  62. LogLength: 100,
  63. },
  64. want: []*actions_model.ActionTaskStep{
  65. {Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
  66. {Status: actions_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
  67. {Name: postStepName, Status: actions_model.StatusWaiting, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
  68. },
  69. },
  70. {
  71. name: "first step has canceled",
  72. task: &actions_model.ActionTask{
  73. Steps: []*actions_model.ActionTaskStep{
  74. {Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
  75. },
  76. Status: actions_model.StatusFailure,
  77. Started: 10000,
  78. Stopped: 10100,
  79. LogLength: 100,
  80. },
  81. want: []*actions_model.ActionTaskStep{
  82. {Name: preStepName, Status: actions_model.StatusFailure, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
  83. {Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
  84. {Name: postStepName, Status: actions_model.StatusFailure, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
  85. },
  86. },
  87. {
  88. name: "empty steps",
  89. task: &actions_model.ActionTask{
  90. Steps: []*actions_model.ActionTaskStep{},
  91. Status: actions_model.StatusSuccess,
  92. Started: 10000,
  93. Stopped: 10100,
  94. LogLength: 100,
  95. },
  96. want: []*actions_model.ActionTaskStep{
  97. {Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
  98. {Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
  99. },
  100. },
  101. }
  102. for _, tt := range tests {
  103. t.Run(tt.name, func(t *testing.T) {
  104. assert.Equalf(t, tt.want, FullSteps(tt.task), "FullSteps(%v)", tt.task)
  105. })
  106. }
  107. }