mirror of
https://github.com/go-task/task.git
synced 2025-01-26 05:27:15 +02:00
6ed30f1add
This shouldn't have any behavior changes for now. This is a code refactor that should allow us to do further improvements on how variables are handled, specially regarding respecting the declaration order in Taskfiles, which should make it easier for the users. Initial work on #218
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package taskfile_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/go-task/task/v2/internal/taskfile"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func TestCmdParse(t *testing.T) {
|
|
const (
|
|
yamlCmd = `echo "a string command"`
|
|
yamlDep = `"task-name"`
|
|
yamlTaskCall = `
|
|
task: another-task
|
|
vars:
|
|
PARAM1: VALUE1
|
|
PARAM2: VALUE2
|
|
`
|
|
)
|
|
tests := []struct {
|
|
content string
|
|
v interface{}
|
|
expected interface{}
|
|
}{
|
|
{
|
|
yamlCmd,
|
|
&taskfile.Cmd{},
|
|
&taskfile.Cmd{Cmd: `echo "a string command"`},
|
|
},
|
|
{
|
|
yamlTaskCall,
|
|
&taskfile.Cmd{},
|
|
&taskfile.Cmd{Task: "another-task", Vars: &taskfile.Vars{
|
|
Keys: []string{"PARAM1", "PARAM2"},
|
|
Mapping: map[string]taskfile.Var{
|
|
"PARAM1": taskfile.Var{Static: "VALUE1"},
|
|
"PARAM2": taskfile.Var{Static: "VALUE2"},
|
|
},
|
|
}},
|
|
},
|
|
{
|
|
yamlDep,
|
|
&taskfile.Dep{},
|
|
&taskfile.Dep{Task: "task-name"},
|
|
},
|
|
{
|
|
yamlTaskCall,
|
|
&taskfile.Dep{},
|
|
&taskfile.Dep{Task: "another-task", Vars: &taskfile.Vars{
|
|
Keys: []string{"PARAM1", "PARAM2"},
|
|
Mapping: map[string]taskfile.Var{
|
|
"PARAM1": taskfile.Var{Static: "VALUE1"},
|
|
"PARAM2": taskfile.Var{Static: "VALUE2"},
|
|
},
|
|
}},
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
err := yaml.Unmarshal([]byte(test.content), test.v)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, test.expected, test.v)
|
|
}
|
|
}
|