mirror of https://github.com/databricks/cli.git
Add unit test for file name execution during rendering (#640)
## Changes Adds a Unit test that directories and files in the file tree are executed as templates
This commit is contained in:
parent
f7a76ff5d8
commit
55e62366fa
|
@ -434,3 +434,28 @@ func TestRendererNonTemplatesAreCreatedAsCopyFiles(t *testing.T) {
|
||||||
assert.Equal(t, r.files[0].(*copyFile).srcPath, "not-a-template")
|
assert.Equal(t, r.files[0].(*copyFile).srcPath, "not-a-template")
|
||||||
assert.Equal(t, r.files[0].DstPath().absPath(), filepath.Join(tmpDir, "not-a-template"))
|
assert.Equal(t, r.files[0].DstPath().absPath(), filepath.Join(tmpDir, "not-a-template"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRendererFileTreeRendering(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
|
r, err := newRenderer(ctx, map[string]any{
|
||||||
|
"dir_name": "my_directory",
|
||||||
|
"file_name": "my_file",
|
||||||
|
}, "./testdata/file-tree-rendering/template", "./testdata/file-tree-rendering/library", tmpDir)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
err = r.walk()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
// Assert in memory representation is created.
|
||||||
|
assert.Len(t, r.files, 1)
|
||||||
|
assert.Equal(t, r.files[0].DstPath().absPath(), filepath.Join(tmpDir, "my_directory", "my_file"))
|
||||||
|
|
||||||
|
err = r.persistToDisk()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Assert files and directories are correctly materialized.
|
||||||
|
assert.DirExists(t, filepath.Join(tmpDir, "my_directory"))
|
||||||
|
assert.FileExists(t, filepath.Join(tmpDir, "my_directory", "my_file"))
|
||||||
|
}
|
||||||
|
|
0
libs/template/testdata/file-tree-rendering/template/{{.dir_name}}/{{.file_name}}.tmpl
vendored
Normal file
0
libs/template/testdata/file-tree-rendering/template/{{.dir_name}}/{{.file_name}}.tmpl
vendored
Normal file
Loading…
Reference in New Issue