mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-12 22:10:25 +00:00
Follow-up to https://code.forgejo.org/forgejo/runner/pulls/1509 -- improves the UX in Forgejo when a reusable workflow is skipped, marking the workflow as skipped rather than succeeded. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. All work and communication must conform to Forgejo's [AI Agreement](https://codeberg.org/forgejo/governance/src/branch/main/AIAgreement.md). There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests for Go changes - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I ran... - [x] `make pr-go` before pushing ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [x] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12412 Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org>
180 lines
7.2 KiB
Go
180 lines
7.2 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"testing"
|
|
|
|
actions_model "forgejo.org/models/actions"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFullSteps(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
task *actions_model.ActionTask
|
|
want []*actions_model.ActionTaskStep
|
|
}{
|
|
{
|
|
name: "regular",
|
|
task: &actions_model.ActionTask{
|
|
Steps: []*actions_model.ActionTaskStep{
|
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
|
|
},
|
|
Status: actions_model.StatusSuccess,
|
|
Started: 10000,
|
|
Stopped: 10100,
|
|
LogLength: 100,
|
|
},
|
|
want: []*actions_model.ActionTaskStep{
|
|
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
|
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
|
|
{Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
|
|
},
|
|
},
|
|
{
|
|
name: "failed step",
|
|
task: &actions_model.ActionTask{
|
|
Steps: []*actions_model.ActionTaskStep{
|
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
|
|
{Status: actions_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
|
|
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
},
|
|
Status: actions_model.StatusFailure,
|
|
Started: 10000,
|
|
Stopped: 10100,
|
|
LogLength: 100,
|
|
},
|
|
want: []*actions_model.ActionTaskStep{
|
|
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
|
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
|
|
{Status: actions_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
|
|
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
{Name: postStepName, Status: actions_model.StatusFailure, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
|
|
},
|
|
},
|
|
{
|
|
name: "first step is running",
|
|
task: &actions_model.ActionTask{
|
|
Steps: []*actions_model.ActionTaskStep{
|
|
{Status: actions_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
|
|
},
|
|
Status: actions_model.StatusRunning,
|
|
Started: 10000,
|
|
Stopped: 10100,
|
|
LogLength: 100,
|
|
},
|
|
want: []*actions_model.ActionTaskStep{
|
|
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
|
|
{Status: actions_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
|
|
{Name: postStepName, Status: actions_model.StatusWaiting, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
},
|
|
},
|
|
{
|
|
name: "first step has canceled",
|
|
task: &actions_model.ActionTask{
|
|
Steps: []*actions_model.ActionTaskStep{
|
|
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
},
|
|
Status: actions_model.StatusFailure,
|
|
Started: 10000,
|
|
Stopped: 10100,
|
|
LogLength: 100,
|
|
},
|
|
want: []*actions_model.ActionTaskStep{
|
|
{Name: preStepName, Status: actions_model.StatusFailure, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
|
|
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
{Name: postStepName, Status: actions_model.StatusFailure, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
|
|
},
|
|
},
|
|
{
|
|
name: "empty steps",
|
|
task: &actions_model.ActionTask{
|
|
Steps: []*actions_model.ActionTaskStep{},
|
|
Status: actions_model.StatusSuccess,
|
|
Started: 10000,
|
|
Stopped: 10100,
|
|
LogLength: 100,
|
|
},
|
|
want: []*actions_model.ActionTaskStep{
|
|
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
|
|
{Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
|
|
},
|
|
},
|
|
{
|
|
name: "all steps finished but task is running",
|
|
task: &actions_model.ActionTask{
|
|
Steps: []*actions_model.ActionTaskStep{
|
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
|
|
},
|
|
Status: actions_model.StatusRunning,
|
|
Started: 10000,
|
|
Stopped: 0,
|
|
LogLength: 100,
|
|
},
|
|
want: []*actions_model.ActionTaskStep{
|
|
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
|
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
|
|
{Name: postStepName, Status: actions_model.StatusRunning, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 0},
|
|
},
|
|
},
|
|
{
|
|
name: "skipped task",
|
|
task: &actions_model.ActionTask{
|
|
Steps: []*actions_model.ActionTaskStep{
|
|
{Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
},
|
|
Status: actions_model.StatusSkipped,
|
|
Started: 0,
|
|
Stopped: 0,
|
|
LogLength: 0,
|
|
},
|
|
want: []*actions_model.ActionTaskStep{
|
|
{Name: preStepName, Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
{Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
{Name: postStepName, Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
},
|
|
},
|
|
{
|
|
name: "first step is skipped",
|
|
task: &actions_model.ActionTask{
|
|
Steps: []*actions_model.ActionTaskStep{
|
|
{Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
|
|
},
|
|
Status: actions_model.StatusSuccess,
|
|
Started: 10000,
|
|
Stopped: 10100,
|
|
LogLength: 100,
|
|
},
|
|
want: []*actions_model.ActionTaskStep{
|
|
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
|
|
{Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
|
|
{Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
|
|
},
|
|
},
|
|
{
|
|
// situation occurs with a reusable workflow's outer job which has no steps
|
|
name: "skipped task w/ zero steps",
|
|
task: &actions_model.ActionTask{
|
|
Steps: []*actions_model.ActionTaskStep{},
|
|
Status: actions_model.StatusSkipped,
|
|
Started: 0,
|
|
Stopped: 0,
|
|
LogLength: 0,
|
|
},
|
|
want: []*actions_model.ActionTaskStep{
|
|
{Name: preStepName, Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
{Name: postStepName, Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equalf(t, tt.want, FullSteps(tt.task), "FullSteps(%v)", tt.task)
|
|
})
|
|
}
|
|
}
|