mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-23 05:42:33 +09:00
Fix the sorting of jobs out of a matrix ## Before <img width="415" height="487" alt="grafik" src="https://github.com/user-attachments/assets/b628adb9-9158-4106-89f1-d8ecaa98f17d" /> ## After <img width="423" height="365" alt="grafik" src="https://github.com/user-attachments/assets/d26223d5-96da-4bdc-bbfe-389101d28cc8" /> --------- Signed-off-by: Nicolas <bircni@icloud.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestActionJobList_SortMatrixGroupsByName(t *testing.T) {
|
|
mk := func(jobID, name string) *ActionRunJob {
|
|
return &ActionRunJob{JobID: jobID, Name: name}
|
|
}
|
|
names := func(jobs ActionJobList) []string {
|
|
out := make([]string, len(jobs))
|
|
for i, j := range jobs {
|
|
out[i] = j.Name
|
|
}
|
|
return out
|
|
}
|
|
|
|
t.Run("matrix group sorted naturally", func(t *testing.T) {
|
|
jobs := ActionJobList{
|
|
mk("build", "build"),
|
|
mk("test", "test (10)"),
|
|
mk("test", "test (2)"),
|
|
mk("test", "test (1)"),
|
|
mk("deploy", "deploy"),
|
|
}
|
|
jobs.SortMatrixGroupsByName()
|
|
assert.Equal(t, []string{"build", "test (1)", "test (2)", "test (10)", "deploy"}, names(jobs))
|
|
})
|
|
|
|
t.Run("non-adjacent same JobID stays in input order", func(t *testing.T) {
|
|
jobs := ActionJobList{
|
|
mk("test", "test (10)"),
|
|
mk("build", "build"),
|
|
mk("test", "test (1)"),
|
|
}
|
|
jobs.SortMatrixGroupsByName()
|
|
assert.Equal(t, []string{"test (10)", "build", "test (1)"}, names(jobs))
|
|
})
|
|
|
|
t.Run("groups stay in input order", func(t *testing.T) {
|
|
jobs := ActionJobList{
|
|
mk("z", "z"),
|
|
mk("a", "a"),
|
|
}
|
|
jobs.SortMatrixGroupsByName()
|
|
assert.Equal(t, []string{"z", "a"}, names(jobs))
|
|
})
|
|
|
|
t.Run("empty and singleton", func(t *testing.T) {
|
|
ActionJobList(nil).SortMatrixGroupsByName()
|
|
jobs := ActionJobList{mk("only", "only")}
|
|
jobs.SortMatrixGroupsByName()
|
|
assert.Equal(t, []string{"only"}, names(jobs))
|
|
})
|
|
}
|