mirror of
https://github.com/go-task/task.git
synced 2024-12-12 10:45:49 +02:00
feat: add parallel test execution to improve runtime (#1882)
This commit is contained in:
parent
b9a5d1c573
commit
4dffab2e0a
@ -11,6 +11,10 @@ linters:
|
||||
- gofumpt
|
||||
- misspell
|
||||
- noctx
|
||||
- paralleltest
|
||||
- tenv
|
||||
- thelper
|
||||
- tparallel
|
||||
|
||||
linters-settings:
|
||||
depguard:
|
||||
|
@ -12,6 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func TestArgs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
Args []string
|
||||
ExpectedCalls []*ast.Call
|
||||
@ -97,6 +99,8 @@ func TestArgs(t *testing.T) {
|
||||
|
||||
for i, test := range tests {
|
||||
t.Run(fmt.Sprintf("TestArgs%d", i+1), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
calls, globals := args.Parse(test.Args...)
|
||||
assert.Equal(t, test.ExpectedCalls, calls)
|
||||
if test.ExpectedGlobals.Len() > 0 || globals.Len() > 0 {
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
)
|
||||
|
||||
func TestNormalizeFilename(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
In, Out string
|
||||
}{
|
||||
|
@ -26,6 +26,8 @@ import (
|
||||
// | false | true | false |
|
||||
// | false | false | false |
|
||||
func TestIsTaskUpToDate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
task *ast.Task
|
||||
@ -150,6 +152,8 @@ func TestIsTaskUpToDate(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mockStatusChecker := mocks.NewStatusCheckable(t)
|
||||
if tt.setupMockStatusChecker != nil {
|
||||
tt.setupMockStatusChecker(mockStatusChecker)
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func TestFromMap(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
m := map[int]string{3: "three", 1: "one", 2: "two"}
|
||||
om := FromMap(m)
|
||||
assert.Len(t, om.m, 3)
|
||||
@ -20,6 +22,8 @@ func TestFromMap(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetGetExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
om := New[int, string]()
|
||||
assert.False(t, om.Exists(1))
|
||||
assert.Equal(t, "", om.Get(1))
|
||||
@ -29,6 +33,8 @@ func TestSetGetExists(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSort(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
om := New[int, string]()
|
||||
om.Set(3, "three")
|
||||
om.Set(1, "one")
|
||||
@ -38,6 +44,8 @@ func TestSort(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSortFunc(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
om := New[int, string]()
|
||||
om.Set(3, "three")
|
||||
om.Set(1, "one")
|
||||
@ -49,6 +57,8 @@ func TestSortFunc(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestKeysValues(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
om := New[int, string]()
|
||||
om.Set(3, "three")
|
||||
om.Set(1, "one")
|
||||
@ -58,6 +68,8 @@ func TestKeysValues(t *testing.T) {
|
||||
}
|
||||
|
||||
func Range(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
om := New[int, string]()
|
||||
om.Set(3, "three")
|
||||
om.Set(1, "one")
|
||||
@ -81,6 +93,8 @@ func Range(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOrderedMapMerge(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
om1 := New[string, int]()
|
||||
om1.Set("a", 1)
|
||||
om1.Set("b", 2)
|
||||
@ -104,6 +118,8 @@ func TestOrderedMapMerge(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalYAML(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
yamlString := `
|
||||
3: three
|
||||
1: one
|
||||
|
@ -19,6 +19,8 @@ import (
|
||||
)
|
||||
|
||||
func TestInterleaved(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var b bytes.Buffer
|
||||
var o output.Output = output.Interleaved{}
|
||||
w, _, _ := o.WrapWriter(&b, io.Discard, "", nil)
|
||||
@ -30,6 +32,8 @@ func TestInterleaved(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGroup(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var b bytes.Buffer
|
||||
var o output.Output = output.Group{}
|
||||
stdOut, stdErr, cleanup := o.WrapWriter(&b, io.Discard, "", nil)
|
||||
@ -48,6 +52,8 @@ func TestGroup(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGroupWithBeginEnd(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tmpl := templater.Cache{
|
||||
Vars: &ast.Vars{
|
||||
OrderedMap: omap.FromMap(map[string]ast.Var{
|
||||
@ -61,6 +67,8 @@ func TestGroupWithBeginEnd(t *testing.T) {
|
||||
End: "::endgroup::",
|
||||
}
|
||||
t.Run("simple", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var b bytes.Buffer
|
||||
w, _, cleanup := o.WrapWriter(&b, io.Discard, "", &tmpl)
|
||||
|
||||
@ -72,6 +80,8 @@ func TestGroupWithBeginEnd(t *testing.T) {
|
||||
assert.Equal(t, "::group::example-value\nfoo\nbar\nbaz\n::endgroup::\n", b.String())
|
||||
})
|
||||
t.Run("no output", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var b bytes.Buffer
|
||||
_, _, cleanup := o.WrapWriter(&b, io.Discard, "", &tmpl)
|
||||
require.NoError(t, cleanup(nil))
|
||||
@ -80,6 +90,8 @@ func TestGroupWithBeginEnd(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGroupErrorOnlySwallowsOutputOnNoError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var b bytes.Buffer
|
||||
var o output.Output = output.Group{
|
||||
ErrorOnly: true,
|
||||
@ -94,6 +106,8 @@ func TestGroupErrorOnlySwallowsOutputOnNoError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGroupErrorOnlyShowsOutputOnError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var b bytes.Buffer
|
||||
var o output.Output = output.Group{
|
||||
ErrorOnly: true,
|
||||
@ -107,7 +121,7 @@ func TestGroupErrorOnlyShowsOutputOnError(t *testing.T) {
|
||||
assert.Equal(t, "std-out\nstd-err\n", b.String())
|
||||
}
|
||||
|
||||
func TestPrefixed(t *testing.T) {
|
||||
func TestPrefixed(t *testing.T) { //nolint:paralleltest // cannot run in parallel
|
||||
var b bytes.Buffer
|
||||
l := &logger.Logger{
|
||||
Color: false,
|
||||
@ -116,7 +130,7 @@ func TestPrefixed(t *testing.T) {
|
||||
var o output.Output = output.NewPrefixed(l)
|
||||
w, _, cleanup := o.WrapWriter(&b, io.Discard, "prefix", nil)
|
||||
|
||||
t.Run("simple use cases", func(t *testing.T) {
|
||||
t.Run("simple use cases", func(t *testing.T) { //nolint:paralleltest // cannot run in parallel
|
||||
b.Reset()
|
||||
|
||||
fmt.Fprintln(w, "foo\nbar")
|
||||
@ -126,7 +140,7 @@ func TestPrefixed(t *testing.T) {
|
||||
require.NoError(t, cleanup(nil))
|
||||
})
|
||||
|
||||
t.Run("multiple writes for a single line", func(t *testing.T) {
|
||||
t.Run("multiple writes for a single line", func(t *testing.T) { //nolint:paralleltest // cannot run in parallel
|
||||
b.Reset()
|
||||
|
||||
for _, char := range []string{"T", "e", "s", "t", "!"} {
|
||||
@ -140,6 +154,8 @@ func TestPrefixed(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPrefixedWithColor(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
color.NoColor = false
|
||||
|
||||
var b bytes.Buffer
|
||||
@ -155,6 +171,8 @@ func TestPrefixedWithColor(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("colors should loop", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for i, w := range writers {
|
||||
b.Reset()
|
||||
|
||||
@ -164,7 +182,11 @@ func TestPrefixedWithColor(t *testing.T) {
|
||||
l.FOutf(&prefix, color, fmt.Sprintf("prefix-%d", i))
|
||||
|
||||
fmt.Fprintln(w, "foo\nbar")
|
||||
assert.Equal(t, fmt.Sprintf("[%s] foo\n[%s] bar\n", prefix.String(), prefix.String()), b.String())
|
||||
assert.Equal(
|
||||
t,
|
||||
fmt.Sprintf("[%s] foo\n[%s] bar\n", prefix.String(), prefix.String()),
|
||||
b.String(),
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func TestAlphaNumericWithRootTasksFirst_Sort(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
task1 := &ast.Task{Task: "task1"}
|
||||
task2 := &ast.Task{Task: "task2"}
|
||||
task3 := &ast.Task{Task: "ns1:task3"}
|
||||
@ -40,6 +42,8 @@ func TestAlphaNumericWithRootTasksFirst_Sort(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := &AlphaNumericWithRootTasksFirst{}
|
||||
s.Sort(tt.tasks)
|
||||
assert.Equal(t, tt.want, tt.tasks)
|
||||
@ -48,6 +52,8 @@ func TestAlphaNumericWithRootTasksFirst_Sort(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAlphaNumeric_Sort(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
task1 := &ast.Task{Task: "task1"}
|
||||
task2 := &ast.Task{Task: "task2"}
|
||||
task3 := &ast.Task{Task: "ns1:task3"}
|
||||
@ -69,6 +75,8 @@ func TestAlphaNumeric_Sort(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := &AlphaNumeric{}
|
||||
s.Sort(tt.tasks)
|
||||
assert.Equal(t, tt.tasks, tt.want)
|
||||
|
@ -13,6 +13,8 @@ import (
|
||||
)
|
||||
|
||||
func TestPrintsDependenciesIfPresent(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
buffer, l := createDummyLogger()
|
||||
task := &ast.Task{
|
||||
Deps: []*ast.Dep{
|
||||
@ -38,6 +40,8 @@ func createDummyLogger() (*bytes.Buffer, logger.Logger) {
|
||||
}
|
||||
|
||||
func TestDoesNotPrintDependenciesIfMissing(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
buffer, l := createDummyLogger()
|
||||
task := &ast.Task{
|
||||
Deps: []*ast.Dep{},
|
||||
@ -49,6 +53,8 @@ func TestDoesNotPrintDependenciesIfMissing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPrintTaskName(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
buffer, l := createDummyLogger()
|
||||
task := &ast.Task{
|
||||
Task: "my-task-name",
|
||||
@ -60,6 +66,8 @@ func TestPrintTaskName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPrintTaskCommandsIfPresent(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
buffer, l := createDummyLogger()
|
||||
task := &ast.Task{
|
||||
Cmds: []*ast.Cmd{
|
||||
@ -78,6 +86,8 @@ func TestPrintTaskCommandsIfPresent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDoesNotPrintCommandIfMissing(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
buffer, l := createDummyLogger()
|
||||
task := &ast.Task{
|
||||
Cmds: []*ast.Cmd{},
|
||||
@ -89,6 +99,8 @@ func TestDoesNotPrintCommandIfMissing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLayout(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
buffer, l := createDummyLogger()
|
||||
task := &ast.Task{
|
||||
Task: "sample-task",
|
||||
@ -123,6 +135,8 @@ commands:
|
||||
}
|
||||
|
||||
func TestPrintDescriptionAsFallback(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
buffer, l := createDummyLogger()
|
||||
taskWithoutSummary := &ast.Task{
|
||||
Desc: "description",
|
||||
@ -150,6 +164,8 @@ func TestPrintDescriptionAsFallback(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPrintAllWithSpaces(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
buffer, l := createDummyLogger()
|
||||
|
||||
t1 := &ast.Task{Task: "t1"}
|
||||
|
371
task_test.go
371
task_test.go
File diff suppressed because it is too large
Load Diff
@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestPlatformParsing(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
Input string
|
||||
ExpectedOS string
|
||||
@ -34,6 +36,8 @@ func TestPlatformParsing(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.Input, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var p Platform
|
||||
err := p.parsePlatform(test.Input)
|
||||
|
||||
|
@ -11,6 +11,8 @@ import (
|
||||
)
|
||||
|
||||
func TestPreconditionParse(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
content string
|
||||
v any
|
||||
|
@ -12,6 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func TestCmdParse(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const (
|
||||
yamlCmd = `echo "a string command"`
|
||||
yamlDep = `"task-name"`
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
)
|
||||
|
||||
func TestGitNode_ssh(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
node, err := NewGitNode("git@github.com:foo/bar.git//Taskfile.yml?ref=main", "", false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "main", node.ref)
|
||||
@ -19,6 +21,8 @@ func TestGitNode_ssh(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGitNode_sshWithDir(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
node, err := NewGitNode("git@github.com:foo/bar.git//directory/Taskfile.yml?ref=main", "", false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "main", node.ref)
|
||||
@ -31,6 +35,8 @@ func TestGitNode_sshWithDir(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGitNode_https(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
node, err := NewGitNode("https://github.com/foo/bar.git//Taskfile.yml?ref=main", "", false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "main", node.ref)
|
||||
@ -43,6 +49,8 @@ func TestGitNode_https(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGitNode_httpsWithDir(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
node, err := NewGitNode("https://github.com/foo/bar.git//directory/Taskfile.yml?ref=main", "", false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "main", node.ref)
|
||||
@ -55,6 +63,8 @@ func TestGitNode_httpsWithDir(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGitNode_FilenameAndDir(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
node, err := NewGitNode("https://github.com/foo/bar.git//directory/Taskfile.yml?ref=main", "", false)
|
||||
assert.NoError(t, err)
|
||||
filename, dir := node.FilenameAndLastDir()
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
)
|
||||
|
||||
func TestScheme(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
scheme, err := getScheme("https://github.com/foo/bar.git")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "git", scheme)
|
||||
|
Loading…
Reference in New Issue
Block a user