2023-11-03 10:44:03 +00:00
|
|
|
package errors_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"go.uber.org/multierr"
|
|
|
|
|
2023-12-08 07:15:08 +00:00
|
|
|
pipeline_errors "go.woodpecker-ci.org/woodpecker/v2/pipeline/errors"
|
2024-04-15 08:04:21 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/pipeline/errors/types"
|
2023-11-03 10:44:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetPipelineErrors(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
title string
|
|
|
|
err error
|
2024-04-15 08:04:21 +00:00
|
|
|
expected []*types.PipelineError
|
2023-11-03 10:44:03 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
title: "nil error",
|
|
|
|
err: nil,
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "warning",
|
2024-04-15 08:04:21 +00:00
|
|
|
err: &types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: true,
|
|
|
|
},
|
2024-04-15 08:04:21 +00:00
|
|
|
expected: []*types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
{
|
|
|
|
IsWarning: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "pipeline error",
|
2024-04-15 08:04:21 +00:00
|
|
|
err: &types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: false,
|
|
|
|
},
|
2024-04-15 08:04:21 +00:00
|
|
|
expected: []*types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
{
|
|
|
|
IsWarning: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "multiple warnings",
|
|
|
|
err: multierr.Combine(
|
2024-04-15 08:04:21 +00:00
|
|
|
&types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: true,
|
|
|
|
},
|
2024-04-15 08:04:21 +00:00
|
|
|
&types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: true,
|
|
|
|
},
|
|
|
|
),
|
2024-04-15 08:04:21 +00:00
|
|
|
expected: []*types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
{
|
|
|
|
IsWarning: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
IsWarning: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "multiple errors and warnings",
|
|
|
|
err: multierr.Combine(
|
2024-04-15 08:04:21 +00:00
|
|
|
&types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: true,
|
|
|
|
},
|
2024-04-15 08:04:21 +00:00
|
|
|
&types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: false,
|
|
|
|
},
|
|
|
|
errors.New("some error"),
|
|
|
|
),
|
2024-04-15 08:04:21 +00:00
|
|
|
expected: []*types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
{
|
|
|
|
IsWarning: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
IsWarning: false,
|
|
|
|
},
|
|
|
|
{
|
2024-04-15 08:04:21 +00:00
|
|
|
Type: types.PipelineErrorTypeGeneric,
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: false,
|
|
|
|
Message: "some error",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
assert.Equalf(t, pipeline_errors.GetPipelineErrors(test.err), test.expected, test.title)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHasBlockingErrors(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
title string
|
|
|
|
err error
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
title: "nil error",
|
|
|
|
err: nil,
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "warning",
|
2024-04-15 08:04:21 +00:00
|
|
|
err: &types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: true,
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "pipeline error",
|
2024-04-15 08:04:21 +00:00
|
|
|
err: &types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: false,
|
|
|
|
},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "multiple warnings",
|
|
|
|
err: multierr.Combine(
|
2024-04-15 08:04:21 +00:00
|
|
|
&types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: true,
|
|
|
|
},
|
2024-04-15 08:04:21 +00:00
|
|
|
&types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: true,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "multiple errors and warnings",
|
|
|
|
err: multierr.Combine(
|
2024-04-15 08:04:21 +00:00
|
|
|
&types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: true,
|
|
|
|
},
|
2024-04-15 08:04:21 +00:00
|
|
|
&types.PipelineError{
|
2023-11-03 10:44:03 +00:00
|
|
|
IsWarning: false,
|
|
|
|
},
|
|
|
|
errors.New("some error"),
|
|
|
|
),
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2024-01-14 18:33:58 +00:00
|
|
|
assert.Equal(t, test.expected, pipeline_errors.HasBlockingErrors(test.err))
|
2023-11-03 10:44:03 +00:00
|
|
|
}
|
|
|
|
}
|