1
0
mirror of https://github.com/go-task/task.git synced 2024-12-12 10:45:49 +02:00
task/taskfile/taskfile_test.go

67 lines
1.3 KiB
Go
Raw Normal View History

package taskfile_test
2017-07-02 20:30:50 +02:00
import (
"testing"
"github.com/go-task/task/v3/taskfile"
2017-07-02 20:30:50 +02:00
"github.com/stretchr/testify/assert"
2020-03-28 16:27:49 +02:00
"gopkg.in/yaml.v3"
2017-07-02 20:30:50 +02:00
)
func TestCmdParse(t *testing.T) {
const (
yamlCmd = `echo "a string command"`
yamlDep = `"task-name"`
yamlTaskCall = `
task: another-task
2017-07-06 01:07:24 +02:00
vars:
2017-07-02 20:30:50 +02:00
PARAM1: VALUE1
PARAM2: VALUE2
`
)
tests := []struct {
content string
v interface{}
expected interface{}
}{
{
yamlCmd,
&taskfile.Cmd{},
&taskfile.Cmd{Cmd: `echo "a string command"`},
2017-07-02 20:30:50 +02:00
},
{
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"},
},
}},
2017-07-02 20:30:50 +02:00
},
{
yamlDep,
&taskfile.Dep{},
&taskfile.Dep{Task: "task-name"},
2017-07-02 20:30:50 +02:00
},
{
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"},
},
}},
2017-07-02 20:30:50 +02:00
},
}
for _, test := range tests {
err := yaml.Unmarshal([]byte(test.content), test.v)
assert.NoError(t, err)
assert.Equal(t, test.expected, test.v)
}
}