@@ -6,6 +6,7 @@ package devtest
66import (
77 mathRand "math/rand/v2"
88 "net/http"
9+ "slices"
910 "strconv"
1011 "strings"
1112 "time"
@@ -17,24 +18,28 @@ import (
1718 "code.gitea.io/gitea/services/context"
1819)
1920
20- func generateMockStepsLog (logCur actions.LogCursor ) (stepsLog []* actions.ViewStepLog ) {
21- mockedLogs := []string {
22- "::group::test group for: step={step}, cursor={cursor}" ,
23- "in group msg for: step={step}, cursor={cursor}" ,
24- "in group msg for: step={step}, cursor={cursor}" ,
25- "in group msg for: step={step}, cursor={cursor}" ,
26- "::endgroup::" ,
21+ type generateMockStepsLogOptions struct {
22+ mockCountFirst int
23+ mockCountGeneral int
24+ groupRepeat int
25+ }
26+
27+ func generateMockStepsLog (logCur actions.LogCursor , opts generateMockStepsLogOptions ) (stepsLog []* actions.ViewStepLog ) {
28+ var mockedLogs []string
29+ mockedLogs = append (mockedLogs , "::group::test group for: step={step}, cursor={cursor}" )
30+ mockedLogs = append (mockedLogs , slices .Repeat ([]string {"in group msg for: step={step}, cursor={cursor}" }, opts .groupRepeat )... )
31+ mockedLogs = append (mockedLogs , "::endgroup::" )
32+ mockedLogs = append (mockedLogs ,
2733 "message for: step={step}, cursor={cursor}" ,
2834 "message for: step={step}, cursor={cursor}" ,
2935 "##[group]test group for: step={step}, cursor={cursor}" ,
3036 "in group msg for: step={step}, cursor={cursor}" ,
3137 "##[endgroup]" ,
32- }
33- cur := logCur .Cursor // usually the cursor is the "file offset", but here we abuse it as "line number" to make the mock easier, intentionally
34- mockCount := util .Iif (logCur .Step == 0 , 3 , 1 )
35- if logCur .Step == 1 && logCur .Cursor == 0 {
36- mockCount = 30 // for the first batch, return as many as possible to test the auto-expand and auto-scroll
37- }
38+ )
39+ // usually the cursor is the "file offset", but here we abuse it as "line number" to make the mock easier, intentionally
40+ cur := logCur .Cursor
41+ // for the first batch, return as many as possible to test the auto-expand and auto-scroll
42+ mockCount := util .Iif (logCur .Cursor == 0 , opts .mockCountFirst , opts .mockCountGeneral )
3843 for i := 0 ; i < mockCount ; i ++ {
3944 logStr := mockedLogs [int (cur )% len (mockedLogs )]
4045 cur ++
@@ -127,21 +132,28 @@ func MockActionsRunsJobs(ctx *context.Context) {
127132 Duration : "3h" ,
128133 })
129134
135+ var mockLogOptions []generateMockStepsLogOptions
130136 resp .State .CurrentJob .Steps = append (resp .State .CurrentJob .Steps , & actions.ViewJobStep {
131137 Summary : "step 0 (mock slow)" ,
132138 Duration : time .Hour .String (),
133139 Status : actions_model .StatusRunning .String (),
134140 })
141+ mockLogOptions = append (mockLogOptions , generateMockStepsLogOptions {mockCountFirst : 30 , mockCountGeneral : 1 , groupRepeat : 3 })
142+
135143 resp .State .CurrentJob .Steps = append (resp .State .CurrentJob .Steps , & actions.ViewJobStep {
136144 Summary : "step 1 (mock fast)" ,
137145 Duration : time .Hour .String (),
138146 Status : actions_model .StatusRunning .String (),
139147 })
148+ mockLogOptions = append (mockLogOptions , generateMockStepsLogOptions {mockCountFirst : 30 , mockCountGeneral : 3 , groupRepeat : 20 })
149+
140150 resp .State .CurrentJob .Steps = append (resp .State .CurrentJob .Steps , & actions.ViewJobStep {
141151 Summary : "step 2 (mock error)" ,
142152 Duration : time .Hour .String (),
143153 Status : actions_model .StatusRunning .String (),
144154 })
155+ mockLogOptions = append (mockLogOptions , generateMockStepsLogOptions {mockCountFirst : 30 , mockCountGeneral : 3 , groupRepeat : 3 })
156+
145157 if len (req .LogCursors ) == 0 {
146158 ctx .JSON (http .StatusOK , resp )
147159 return
@@ -156,7 +168,7 @@ func MockActionsRunsJobs(ctx *context.Context) {
156168 }
157169 doSlowResponse = doSlowResponse || logCur .Step == 0
158170 doErrorResponse = doErrorResponse || logCur .Step == 2
159- resp .Logs .StepsLog = append (resp .Logs .StepsLog , generateMockStepsLog (logCur )... )
171+ resp .Logs .StepsLog = append (resp .Logs .StepsLog , generateMockStepsLog (logCur , mockLogOptions [ logCur . Step ] )... )
160172 }
161173 if doErrorResponse {
162174 if mathRand .Float64 () > 0.5 {
0 commit comments