1
0
mirror of https://github.com/go-task/task.git synced 2025-02-19 19:44:13 +02:00
task/taskfile/precondition_test.go

49 lines
985 B
Go
Raw Normal View History

2019-05-17 13:13:47 -07:00
package taskfile_test
import (
"testing"
"github.com/stretchr/testify/assert"
2020-03-28 11:27:49 -03:00
"gopkg.in/yaml.v3"
"github.com/go-task/task/v3/taskfile"
2019-05-17 13:13:47 -07:00
)
func TestPreconditionParse(t *testing.T) {
tests := []struct {
content string
v interface{}
expected interface{}
}{
{
"test -f foo.txt",
&taskfile.Precondition{},
2019-05-28 13:02:59 -07:00
&taskfile.Precondition{Sh: `test -f foo.txt`, Msg: "`test -f foo.txt` failed"},
2019-05-17 13:13:47 -07:00
},
{
"sh: '[ 1 = 0 ]'",
&taskfile.Precondition{},
2019-05-28 13:02:59 -07:00
&taskfile.Precondition{Sh: "[ 1 = 0 ]", Msg: "[ 1 = 0 ] failed"},
2019-05-17 13:13:47 -07:00
},
{`
sh: "[ 1 = 2 ]"
msg: "1 is not 2"
`,
&taskfile.Precondition{},
2019-05-28 13:02:59 -07:00
&taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"},
2019-05-17 13:13:47 -07:00
},
{`
sh: "[ 1 = 2 ]"
msg: "1 is not 2"
`,
&taskfile.Precondition{},
2019-05-28 13:02:59 -07:00
&taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"},
2019-05-17 13:13:47 -07:00
},
}
for _, test := range tests {
err := yaml.Unmarshal([]byte(test.content), test.v)
assert.NoError(t, err)
assert.Equal(t, test.expected, test.v)
}
}