mirror of
https://gitea.com/gitea/runner.git
synced 2026-08-25 13:27:46 +00:00
7b4356c746
A `GetMatrixes` error was logged and discarded, leaving a nil matrix list. That collapsed `maxParallel` to zero, so no executor was built and the parallel executor returned nil for an empty list: the job reported success without running anything. It now fails the run. Every error it returns is a workflow validation failure that GitHub rejects too, so nothing that runs there starts failing here. Reviewed-on: https://gitea.com/gitea/runner/pulls/1187 Reviewed-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io>
85 lines
2.0 KiB
Go
85 lines
2.0 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package runner
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.dev/actionslib/pkg/model"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.yaml.in/yaml/v4"
|
|
)
|
|
|
|
func TestMaxParallelStrategy(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
maxParallelString string
|
|
expectedMaxParallel int
|
|
}{
|
|
{
|
|
name: "max-parallel-1",
|
|
maxParallelString: "1",
|
|
expectedMaxParallel: 1,
|
|
},
|
|
{
|
|
name: "max-parallel-2",
|
|
maxParallelString: "2",
|
|
expectedMaxParallel: 2,
|
|
},
|
|
{
|
|
name: "max-parallel-default",
|
|
maxParallelString: "",
|
|
expectedMaxParallel: 4,
|
|
},
|
|
{
|
|
name: "max-parallel-10",
|
|
maxParallelString: "10",
|
|
expectedMaxParallel: 10,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
matrix := map[string][]any{
|
|
"version": {1, 2, 3, 4, 5},
|
|
}
|
|
|
|
var rawMatrix yaml.Node
|
|
err := rawMatrix.Encode(matrix)
|
|
assert.NoError(t, err) //nolint:testifylint // pre-existing issue from nektos/act
|
|
|
|
job := &model.Job{
|
|
Strategy: &model.Strategy{
|
|
MaxParallelString: tt.maxParallelString,
|
|
RawMatrix: rawMatrix,
|
|
},
|
|
}
|
|
|
|
matrixes, err := job.GetMatrixes()
|
|
assert.NoError(t, err) //nolint:testifylint // pre-existing issue from nektos/act
|
|
assert.NotNil(t, matrixes)
|
|
assert.Len(t, matrixes, 5)
|
|
assert.Equal(t, tt.expectedMaxParallel, job.Strategy.MaxParallel)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewPlanExecutorInvalidMatrix(t *testing.T) {
|
|
var rawMatrix yaml.Node
|
|
require.NoError(t, rawMatrix.Encode(map[string]any{
|
|
"config": map[string]any{"nested": "value"},
|
|
}))
|
|
|
|
plan := &model.Plan{Stages: []*model.Stage{{Runs: []*model.Run{{
|
|
Workflow: &model.Workflow{Jobs: map[string]*model.Job{
|
|
"test": {Strategy: &model.Strategy{RawMatrix: rawMatrix}},
|
|
}},
|
|
JobID: "test",
|
|
}}}}}
|
|
runner := &runnerImpl{config: &Config{}}
|
|
|
|
require.ErrorContains(t, runner.NewPlanExecutor(plan)(t.Context()), "could not get job matrix:")
|
|
}
|