mirror of
https://github.com/go-task/task.git
synced 2025-02-01 13:17:56 +02:00
Add dynamic variable w/in-existent dir test
Add test for when there is a dynamic variable that relies on the existence of a directory that go task creates.
This commit is contained in:
parent
d75536bf00
commit
a6b02dc6ba
28
task_test.go
28
task_test.go
@ -1528,6 +1528,34 @@ func TestDynamicVariablesRunOnTheNewCreatedDir(t *testing.T) {
|
||||
_ = os.RemoveAll(toBeCreated)
|
||||
}
|
||||
|
||||
func TestExplicitDynamicVariablesRunOnTheNewCreatedDir(t *testing.T) {
|
||||
const expected = "created"
|
||||
const dir = "testdata/dir/explicit_dynamic_var_on_created_dir/"
|
||||
const toBeCreated = dir + expected
|
||||
const target = "default"
|
||||
var out bytes.Buffer
|
||||
e := &task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &out,
|
||||
Stderr: &out,
|
||||
}
|
||||
|
||||
// Ensure that the directory to be created doesn't actually exist.
|
||||
_ = os.RemoveAll(toBeCreated)
|
||||
if _, err := os.Stat(toBeCreated); err == nil {
|
||||
t.Errorf("Directory should not exist: %v", err)
|
||||
}
|
||||
|
||||
require.NoError(t, e.Setup())
|
||||
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: target}))
|
||||
|
||||
got := strings.TrimSuffix(filepath.Base(out.String()), "\n")
|
||||
assert.Equal(t, expected, got, "Mismatch in the working directory")
|
||||
|
||||
// Clean-up after ourselves only if no error.
|
||||
_ = os.RemoveAll(toBeCreated)
|
||||
}
|
||||
|
||||
func TestDynamicVariablesShouldRunOnTheTaskDir(t *testing.T) {
|
||||
tt := fileContentTest{
|
||||
Dir: "testdata/dir/dynamic_var",
|
||||
|
11
testdata/dir/explicit_dynamic_var_on_created_dir/Taskfile.yml
vendored
Normal file
11
testdata/dir/explicit_dynamic_var_on_created_dir/Taskfile.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
dir: created
|
||||
vars:
|
||||
TEST_VAR:
|
||||
sh: echo test > created && echo created
|
||||
cmds:
|
||||
- |
|
||||
echo "/{{.TEST_VAR}}"
|
Loading…
x
Reference in New Issue
Block a user