mirror of
https://github.com/go-task/task.git
synced 2025-03-03 14:52:13 +02:00
* feat: remote taskfiles over http * feat: allow insecure connections when --insecure flag is provided * feat: better error handling for fetch errors * fix: ensure cache directory always exists * fix: setup logger before everything else * feat: put remote taskfiles behind an experiment * feat: --download and --offline flags for remote taskfiles * feat: node.Read accepts a context * feat: experiment docs * chore: changelog * chore: remove unused optional param from Node interface * chore: tidy up and generalise NewNode function * fix: use sha256 in remote checksum * feat: --download by itself will not run a task * feat: custom error if remote taskfiles experiment is not enabled * refactor: BaseNode functional options and simplified FileNode * fix: use hex encoding for checksum instead of b64
220 lines
5.1 KiB
Go
220 lines
5.1 KiB
Go
package args_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/go-task/task/v3/args"
|
|
"github.com/go-task/task/v3/internal/orderedmap"
|
|
"github.com/go-task/task/v3/taskfile"
|
|
)
|
|
|
|
func TestArgsV3(t *testing.T) {
|
|
tests := []struct {
|
|
Args []string
|
|
ExpectedCalls []taskfile.Call
|
|
ExpectedGlobals *taskfile.Vars
|
|
}{
|
|
{
|
|
Args: []string{"task-a", "task-b", "task-c"},
|
|
ExpectedCalls: []taskfile.Call{
|
|
{Task: "task-a", Direct: true},
|
|
{Task: "task-b", Direct: true},
|
|
{Task: "task-c", Direct: true},
|
|
},
|
|
},
|
|
{
|
|
Args: []string{"task-a", "FOO=bar", "task-b", "task-c", "BAR=baz", "BAZ=foo"},
|
|
ExpectedCalls: []taskfile.Call{
|
|
{Task: "task-a", Direct: true},
|
|
{Task: "task-b", Direct: true},
|
|
{Task: "task-c", Direct: true},
|
|
},
|
|
ExpectedGlobals: &taskfile.Vars{
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
map[string]taskfile.Var{
|
|
"FOO": {Static: "bar"},
|
|
"BAR": {Static: "baz"},
|
|
"BAZ": {Static: "foo"},
|
|
},
|
|
[]string{"FOO", "BAR", "BAZ"},
|
|
),
|
|
},
|
|
},
|
|
{
|
|
Args: []string{"task-a", "CONTENT=with some spaces"},
|
|
ExpectedCalls: []taskfile.Call{
|
|
{Task: "task-a", Direct: true},
|
|
},
|
|
ExpectedGlobals: &taskfile.Vars{
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
map[string]taskfile.Var{
|
|
"CONTENT": {Static: "with some spaces"},
|
|
},
|
|
[]string{"CONTENT"},
|
|
),
|
|
},
|
|
},
|
|
{
|
|
Args: []string{"FOO=bar", "task-a", "task-b"},
|
|
ExpectedCalls: []taskfile.Call{
|
|
{Task: "task-a", Direct: true},
|
|
{Task: "task-b", Direct: true},
|
|
},
|
|
ExpectedGlobals: &taskfile.Vars{
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
map[string]taskfile.Var{
|
|
"FOO": {Static: "bar"},
|
|
},
|
|
[]string{"FOO"},
|
|
),
|
|
},
|
|
},
|
|
{
|
|
Args: nil,
|
|
ExpectedCalls: []taskfile.Call{},
|
|
},
|
|
{
|
|
Args: []string{},
|
|
ExpectedCalls: []taskfile.Call{},
|
|
},
|
|
{
|
|
Args: []string{"FOO=bar", "BAR=baz"},
|
|
ExpectedCalls: []taskfile.Call{},
|
|
ExpectedGlobals: &taskfile.Vars{
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
map[string]taskfile.Var{
|
|
"FOO": {Static: "bar"},
|
|
"BAR": {Static: "baz"},
|
|
},
|
|
[]string{"FOO", "BAR"},
|
|
),
|
|
},
|
|
},
|
|
}
|
|
|
|
for i, test := range tests {
|
|
t.Run(fmt.Sprintf("TestArgs%d", i+1), func(t *testing.T) {
|
|
calls, globals := args.ParseV3(test.Args...)
|
|
assert.Equal(t, test.ExpectedCalls, calls)
|
|
if test.ExpectedGlobals.Len() > 0 || globals.Len() > 0 {
|
|
assert.Equal(t, test.ExpectedGlobals.Keys(), globals.Keys())
|
|
assert.Equal(t, test.ExpectedGlobals.Values(), globals.Values())
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestArgsV2(t *testing.T) {
|
|
tests := []struct {
|
|
Args []string
|
|
ExpectedCalls []taskfile.Call
|
|
ExpectedGlobals *taskfile.Vars
|
|
}{
|
|
{
|
|
Args: []string{"task-a", "task-b", "task-c"},
|
|
ExpectedCalls: []taskfile.Call{
|
|
{Task: "task-a", Direct: true},
|
|
{Task: "task-b", Direct: true},
|
|
{Task: "task-c", Direct: true},
|
|
},
|
|
},
|
|
{
|
|
Args: []string{"task-a", "FOO=bar", "task-b", "task-c", "BAR=baz", "BAZ=foo"},
|
|
ExpectedCalls: []taskfile.Call{
|
|
{
|
|
Task: "task-a",
|
|
Direct: true,
|
|
Vars: &taskfile.Vars{
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
map[string]taskfile.Var{
|
|
"FOO": {Static: "bar"},
|
|
},
|
|
[]string{"FOO"},
|
|
),
|
|
},
|
|
},
|
|
{Task: "task-b", Direct: true},
|
|
{
|
|
Task: "task-c",
|
|
Direct: true,
|
|
Vars: &taskfile.Vars{
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
map[string]taskfile.Var{
|
|
"BAR": {Static: "baz"},
|
|
"BAZ": {Static: "foo"},
|
|
},
|
|
[]string{"BAR", "BAZ"},
|
|
),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Args: []string{"task-a", "CONTENT=with some spaces"},
|
|
ExpectedCalls: []taskfile.Call{
|
|
{
|
|
Task: "task-a",
|
|
Direct: true,
|
|
Vars: &taskfile.Vars{
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
map[string]taskfile.Var{
|
|
"CONTENT": {Static: "with some spaces"},
|
|
},
|
|
[]string{"CONTENT"},
|
|
),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Args: []string{"FOO=bar", "task-a", "task-b"},
|
|
ExpectedCalls: []taskfile.Call{
|
|
{Task: "task-a", Direct: true},
|
|
{Task: "task-b", Direct: true},
|
|
},
|
|
ExpectedGlobals: &taskfile.Vars{
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
map[string]taskfile.Var{
|
|
"FOO": {Static: "bar"},
|
|
},
|
|
[]string{"FOO"},
|
|
),
|
|
},
|
|
},
|
|
{
|
|
Args: nil,
|
|
ExpectedCalls: []taskfile.Call{},
|
|
},
|
|
{
|
|
Args: []string{},
|
|
ExpectedCalls: []taskfile.Call{},
|
|
},
|
|
{
|
|
Args: []string{"FOO=bar", "BAR=baz"},
|
|
ExpectedCalls: []taskfile.Call{},
|
|
ExpectedGlobals: &taskfile.Vars{
|
|
OrderedMap: orderedmap.FromMapWithOrder(
|
|
map[string]taskfile.Var{
|
|
"FOO": {Static: "bar"},
|
|
"BAR": {Static: "baz"},
|
|
},
|
|
[]string{"FOO", "BAR"},
|
|
),
|
|
},
|
|
},
|
|
}
|
|
|
|
for i, test := range tests {
|
|
t.Run(fmt.Sprintf("TestArgs%d", i+1), func(t *testing.T) {
|
|
calls, globals := args.ParseV2(test.Args...)
|
|
assert.Equal(t, test.ExpectedCalls, calls)
|
|
if test.ExpectedGlobals.Len() > 0 || globals.Len() > 0 {
|
|
assert.Equal(t, test.ExpectedGlobals, globals)
|
|
}
|
|
})
|
|
}
|
|
}
|