1
0
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:
Wolf Mermelstein 2024-09-30 15:58:34 -04:00
parent d75536bf00
commit a6b02dc6ba
2 changed files with 39 additions and 0 deletions

View File

@ -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",

View File

@ -0,0 +1,11 @@
version: '3'
tasks:
default:
dir: created
vars:
TEST_VAR:
sh: echo test > created && echo created
cmds:
- |
echo "/{{.TEST_VAR}}"