mirror of https://github.com/databricks/cli.git
Read template from [fs.FS] instead of assuming local paths
This removes the need to pre-materialize built-in templates.
This commit is contained in:
parent
7d732ceba8
commit
4621079f71
|
@ -3,7 +3,9 @@ package jsonschema
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
|
@ -255,7 +257,12 @@ func (schema *Schema) validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load(path string) (*Schema, error) {
|
func Load(path string) (*Schema, error) {
|
||||||
b, err := os.ReadFile(path)
|
dir, file := filepath.Split(path)
|
||||||
|
return LoadFS(os.DirFS(dir), file)
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadFS(fsys fs.FS, path string) (*Schema, error) {
|
||||||
|
b, err := fs.ReadFile(fsys, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package jsonschema
|
package jsonschema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -305,3 +306,9 @@ func TestValidateSchemaSkippedPropertiesHaveDefaults(t *testing.T) {
|
||||||
err = s.validate()
|
err = s.validate()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSchema_LoadFS(t *testing.T) {
|
||||||
|
fsys := os.DirFS("./testdata/schema-load-int")
|
||||||
|
_, err := LoadFS(fsys, "schema-valid.json")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/cmdio"
|
"github.com/databricks/cli/libs/cmdio"
|
||||||
"github.com/databricks/cli/libs/jsonschema"
|
"github.com/databricks/cli/libs/jsonschema"
|
||||||
|
@ -28,9 +29,8 @@ type config struct {
|
||||||
schema *jsonschema.Schema
|
schema *jsonschema.Schema
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConfig(ctx context.Context, schemaPath string) (*config, error) {
|
func newConfig(ctx context.Context, templateRoot fs.FS, schemaPath string) (*config, error) {
|
||||||
// Read config schema
|
schema, err := jsonschema.LoadFS(templateRoot, schemaPath)
|
||||||
schema, err := jsonschema.Load(schemaPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package template
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
@ -16,7 +17,7 @@ func TestTemplateConfigAssignValuesFromFile(t *testing.T) {
|
||||||
testDir := "./testdata/config-assign-from-file"
|
testDir := "./testdata/config-assign-from-file"
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := newConfig(ctx, filepath.Join(testDir, "schema.json"))
|
c, err := newConfig(ctx, os.DirFS(testDir), "schema.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = c.assignValuesFromFile(filepath.Join(testDir, "config.json"))
|
err = c.assignValuesFromFile(filepath.Join(testDir, "config.json"))
|
||||||
|
@ -32,7 +33,7 @@ func TestTemplateConfigAssignValuesFromFileDoesNotOverwriteExistingConfigs(t *te
|
||||||
testDir := "./testdata/config-assign-from-file"
|
testDir := "./testdata/config-assign-from-file"
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := newConfig(ctx, filepath.Join(testDir, "schema.json"))
|
c, err := newConfig(ctx, os.DirFS(testDir), "schema.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
c.values = map[string]any{
|
c.values = map[string]any{
|
||||||
|
@ -52,7 +53,7 @@ func TestTemplateConfigAssignValuesFromFileForInvalidIntegerValue(t *testing.T)
|
||||||
testDir := "./testdata/config-assign-from-file-invalid-int"
|
testDir := "./testdata/config-assign-from-file-invalid-int"
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := newConfig(ctx, filepath.Join(testDir, "schema.json"))
|
c, err := newConfig(ctx, os.DirFS(testDir), "schema.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = c.assignValuesFromFile(filepath.Join(testDir, "config.json"))
|
err = c.assignValuesFromFile(filepath.Join(testDir, "config.json"))
|
||||||
|
@ -63,7 +64,7 @@ func TestTemplateConfigAssignValuesFromFileFiltersPropertiesNotInTheSchema(t *te
|
||||||
testDir := "./testdata/config-assign-from-file-unknown-property"
|
testDir := "./testdata/config-assign-from-file-unknown-property"
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := newConfig(ctx, filepath.Join(testDir, "schema.json"))
|
c, err := newConfig(ctx, os.DirFS(testDir), "schema.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = c.assignValuesFromFile(filepath.Join(testDir, "config.json"))
|
err = c.assignValuesFromFile(filepath.Join(testDir, "config.json"))
|
||||||
|
@ -78,10 +79,10 @@ func TestTemplateConfigAssignValuesFromDefaultValues(t *testing.T) {
|
||||||
testDir := "./testdata/config-assign-from-default-value"
|
testDir := "./testdata/config-assign-from-default-value"
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := newConfig(ctx, filepath.Join(testDir, "schema.json"))
|
c, err := newConfig(ctx, os.DirFS(testDir), "schema.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
r, err := newRenderer(ctx, nil, nil, "./testdata/empty/template", "./testdata/empty/library", t.TempDir())
|
r, err := newRenderer(ctx, nil, nil, os.DirFS("."), "./testdata/empty/template", "./testdata/empty/library", t.TempDir())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = c.assignDefaultValues(r)
|
err = c.assignDefaultValues(r)
|
||||||
|
@ -97,10 +98,10 @@ func TestTemplateConfigAssignValuesFromTemplatedDefaultValues(t *testing.T) {
|
||||||
testDir := "./testdata/config-assign-from-templated-default-value"
|
testDir := "./testdata/config-assign-from-templated-default-value"
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := newConfig(ctx, filepath.Join(testDir, "schema.json"))
|
c, err := newConfig(ctx, os.DirFS(testDir), "schema.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
r, err := newRenderer(ctx, nil, nil, filepath.Join(testDir, "template/template"), filepath.Join(testDir, "template/library"), t.TempDir())
|
r, err := newRenderer(ctx, nil, nil, os.DirFS("."), filepath.Join(testDir, "template/template"), filepath.Join(testDir, "template/library"), t.TempDir())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Note: only the string value is templated.
|
// Note: only the string value is templated.
|
||||||
|
@ -116,7 +117,7 @@ func TestTemplateConfigAssignValuesFromTemplatedDefaultValues(t *testing.T) {
|
||||||
|
|
||||||
func TestTemplateConfigValidateValuesDefined(t *testing.T) {
|
func TestTemplateConfigValidateValuesDefined(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := newConfig(ctx, "testdata/config-test-schema/test-schema.json")
|
c, err := newConfig(ctx, os.DirFS("testdata/config-test-schema"), "test-schema.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
c.values = map[string]any{
|
c.values = map[string]any{
|
||||||
|
@ -131,7 +132,7 @@ func TestTemplateConfigValidateValuesDefined(t *testing.T) {
|
||||||
|
|
||||||
func TestTemplateConfigValidateTypeForValidConfig(t *testing.T) {
|
func TestTemplateConfigValidateTypeForValidConfig(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := newConfig(ctx, "testdata/config-test-schema/test-schema.json")
|
c, err := newConfig(ctx, os.DirFS("testdata/config-test-schema"), "test-schema.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
c.values = map[string]any{
|
c.values = map[string]any{
|
||||||
|
@ -147,7 +148,7 @@ func TestTemplateConfigValidateTypeForValidConfig(t *testing.T) {
|
||||||
|
|
||||||
func TestTemplateConfigValidateTypeForUnknownField(t *testing.T) {
|
func TestTemplateConfigValidateTypeForUnknownField(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := newConfig(ctx, "testdata/config-test-schema/test-schema.json")
|
c, err := newConfig(ctx, os.DirFS("testdata/config-test-schema"), "test-schema.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
c.values = map[string]any{
|
c.values = map[string]any{
|
||||||
|
@ -164,7 +165,7 @@ func TestTemplateConfigValidateTypeForUnknownField(t *testing.T) {
|
||||||
|
|
||||||
func TestTemplateConfigValidateTypeForInvalidType(t *testing.T) {
|
func TestTemplateConfigValidateTypeForInvalidType(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := newConfig(ctx, "testdata/config-test-schema/test-schema.json")
|
c, err := newConfig(ctx, os.DirFS("testdata/config-test-schema"), "test-schema.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
c.values = map[string]any{
|
c.values = map[string]any{
|
||||||
|
@ -271,7 +272,8 @@ func TestTemplateEnumValidation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTemplateSchemaErrorsWithEmptyDescription(t *testing.T) {
|
func TestTemplateSchemaErrorsWithEmptyDescription(t *testing.T) {
|
||||||
_, err := newConfig(context.Background(), "./testdata/config-test-schema/invalid-test-schema.json")
|
ctx := context.Background()
|
||||||
|
_, err := newConfig(ctx, os.DirFS("./testdata/config-test-schema"), "invalid-test-schema.json")
|
||||||
assert.EqualError(t, err, "template property property-without-description is missing a description")
|
assert.EqualError(t, err, "template property property-without-description is missing a description")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,7 @@ import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"github.com/databricks/cli/libs/filer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Interface representing a file to be materialized from a template into a project
|
// Interface representing a file to be materialized from a template into a project
|
||||||
|
@ -19,6 +18,10 @@ type file interface {
|
||||||
|
|
||||||
// Write file to disk at the destination path.
|
// Write file to disk at the destination path.
|
||||||
PersistToDisk() error
|
PersistToDisk() error
|
||||||
|
|
||||||
|
// contents returns the file contents as a byte slice.
|
||||||
|
// This is used for testing purposes.
|
||||||
|
contents() ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type destinationPath struct {
|
type destinationPath struct {
|
||||||
|
@ -46,8 +49,8 @@ type copyFile struct {
|
||||||
|
|
||||||
dstPath *destinationPath
|
dstPath *destinationPath
|
||||||
|
|
||||||
// Filer rooted at template root. Used to read srcPath.
|
// [fs.FS] rooted at template root. Used to read srcPath.
|
||||||
srcFiler filer.Filer
|
srcFS fs.FS
|
||||||
|
|
||||||
// Relative path from template root for file to be copied.
|
// Relative path from template root for file to be copied.
|
||||||
srcPath string
|
srcPath string
|
||||||
|
@ -63,7 +66,7 @@ func (f *copyFile) PersistToDisk() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
srcFile, err := f.srcFiler.Read(f.ctx, f.srcPath)
|
srcFile, err := f.srcFS.Open(f.srcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -77,6 +80,10 @@ func (f *copyFile) PersistToDisk() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *copyFile) contents() ([]byte, error) {
|
||||||
|
return fs.ReadFile(f.srcFS, f.srcPath)
|
||||||
|
}
|
||||||
|
|
||||||
type inMemoryFile struct {
|
type inMemoryFile struct {
|
||||||
dstPath *destinationPath
|
dstPath *destinationPath
|
||||||
|
|
||||||
|
@ -99,3 +106,7 @@ func (f *inMemoryFile) PersistToDisk() error {
|
||||||
}
|
}
|
||||||
return os.WriteFile(path, f.content, f.perm)
|
return os.WriteFile(path, f.content, f.perm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *inMemoryFile) contents() ([]byte, error) {
|
||||||
|
return slices.Clone(f.content), nil
|
||||||
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/filer"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -33,10 +32,7 @@ func testInMemoryFile(t *testing.T, perm fs.FileMode) {
|
||||||
|
|
||||||
func testCopyFile(t *testing.T, perm fs.FileMode) {
|
func testCopyFile(t *testing.T, perm fs.FileMode) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
err := os.WriteFile(filepath.Join(tmpDir, "source"), []byte("qwerty"), perm)
|
||||||
templateFiler, err := filer.NewLocalClient(tmpDir)
|
|
||||||
require.NoError(t, err)
|
|
||||||
err = os.WriteFile(filepath.Join(tmpDir, "source"), []byte("qwerty"), perm)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
f := ©File{
|
f := ©File{
|
||||||
|
@ -45,9 +41,9 @@ func testCopyFile(t *testing.T, perm fs.FileMode) {
|
||||||
root: tmpDir,
|
root: tmpDir,
|
||||||
relPath: "a/b/c",
|
relPath: "a/b/c",
|
||||||
},
|
},
|
||||||
perm: perm,
|
perm: perm,
|
||||||
srcPath: "source",
|
srcPath: "source",
|
||||||
srcFiler: templateFiler,
|
srcFS: os.DirFS(tmpDir),
|
||||||
}
|
}
|
||||||
err = f.PersistToDisk()
|
err = f.PersistToDisk()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestTemplatePrintStringWithoutProcessing(t *testing.T) {
|
||||||
|
|
||||||
ctx = root.SetWorkspaceClient(ctx, nil)
|
ctx = root.SetWorkspaceClient(ctx, nil)
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/print-without-processing/template", "./testdata/print-without-processing/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/print-without-processing/template", "./testdata/print-without-processing/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -39,7 +39,7 @@ func TestTemplateRegexpCompileFunction(t *testing.T) {
|
||||||
|
|
||||||
ctx = root.SetWorkspaceClient(ctx, nil)
|
ctx = root.SetWorkspaceClient(ctx, nil)
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/regexp-compile/template", "./testdata/regexp-compile/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/regexp-compile/template", "./testdata/regexp-compile/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -57,7 +57,7 @@ func TestTemplateRandIntFunction(t *testing.T) {
|
||||||
|
|
||||||
ctx = root.SetWorkspaceClient(ctx, nil)
|
ctx = root.SetWorkspaceClient(ctx, nil)
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/random-int/template", "./testdata/random-int/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/random-int/template", "./testdata/random-int/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -75,7 +75,7 @@ func TestTemplateUuidFunction(t *testing.T) {
|
||||||
|
|
||||||
ctx = root.SetWorkspaceClient(ctx, nil)
|
ctx = root.SetWorkspaceClient(ctx, nil)
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/uuid/template", "./testdata/uuid/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/uuid/template", "./testdata/uuid/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -92,7 +92,7 @@ func TestTemplateUrlFunction(t *testing.T) {
|
||||||
|
|
||||||
ctx = root.SetWorkspaceClient(ctx, nil)
|
ctx = root.SetWorkspaceClient(ctx, nil)
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/urlparse-function/template", "./testdata/urlparse-function/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/urlparse-function/template", "./testdata/urlparse-function/library", tmpDir)
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ func TestTemplateMapPairFunction(t *testing.T) {
|
||||||
|
|
||||||
ctx = root.SetWorkspaceClient(ctx, nil)
|
ctx = root.SetWorkspaceClient(ctx, nil)
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/map-pair/template", "./testdata/map-pair/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/map-pair/template", "./testdata/map-pair/library", tmpDir)
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ func TestWorkspaceHost(t *testing.T) {
|
||||||
ctx = root.SetWorkspaceClient(ctx, w)
|
ctx = root.SetWorkspaceClient(ctx, w)
|
||||||
|
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/workspace-host/template", "./testdata/map-pair/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/workspace-host/template", "./testdata/map-pair/library", tmpDir)
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ func TestWorkspaceHostNotConfigured(t *testing.T) {
|
||||||
ctx = root.SetWorkspaceClient(ctx, w)
|
ctx = root.SetWorkspaceClient(ctx, w)
|
||||||
|
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/workspace-host/template", "./testdata/map-pair/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/workspace-host/template", "./testdata/map-pair/library", tmpDir)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/cmdio"
|
"github.com/databricks/cli/libs/cmdio"
|
||||||
)
|
)
|
||||||
|
@ -28,28 +25,12 @@ var builtinTemplates embed.FS
|
||||||
// configFilePath: file path containing user defined config values
|
// configFilePath: file path containing user defined config values
|
||||||
// templateRoot: root of the template definition
|
// templateRoot: root of the template definition
|
||||||
// outputDir: root of directory where to initialize the template
|
// outputDir: root of directory where to initialize the template
|
||||||
func Materialize(ctx context.Context, configFilePath, templateRoot, outputDir string) error {
|
func Materialize(ctx context.Context, configFilePath string, templateRoot fs.FS, outputDir string) error {
|
||||||
// Use a temporary directory in case any builtin templates like default-python are used
|
if _, err := fs.Stat(templateRoot, schemaFileName); errors.Is(err, fs.ErrNotExist) {
|
||||||
tempDir, err := os.MkdirTemp("", "templates")
|
return fmt.Errorf("not a bundle template: expected to find a template schema file at %s", schemaFileName)
|
||||||
defer os.RemoveAll(tempDir)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
templateRoot, err = prepareBuiltinTemplates(templateRoot, tempDir)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
templatePath := filepath.Join(templateRoot, templateDirName)
|
config, err := newConfig(ctx, templateRoot, schemaFileName)
|
||||||
libraryPath := filepath.Join(templateRoot, libraryDirName)
|
|
||||||
schemaPath := filepath.Join(templateRoot, schemaFileName)
|
|
||||||
helpers := loadHelpers(ctx)
|
|
||||||
|
|
||||||
if _, err := os.Stat(schemaPath); errors.Is(err, fs.ErrNotExist) {
|
|
||||||
return fmt.Errorf("not a bundle template: expected to find a template schema file at %s", schemaPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
config, err := newConfig(ctx, schemaPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -62,7 +43,8 @@ func Materialize(ctx context.Context, configFilePath, templateRoot, outputDir st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := newRenderer(ctx, config.values, helpers, templatePath, libraryPath, outputDir)
|
helpers := loadHelpers(ctx)
|
||||||
|
r, err := newRenderer(ctx, config.values, helpers, templateRoot, templateDirName, libraryDirName, outputDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -111,44 +93,3 @@ func Materialize(ctx context.Context, configFilePath, templateRoot, outputDir st
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the given templateRoot matches
|
|
||||||
func prepareBuiltinTemplates(templateRoot string, tempDir string) (string, error) {
|
|
||||||
// Check that `templateRoot` is a clean basename, i.e. `some_path` and not `./some_path` or "."
|
|
||||||
// Return early if that's not the case.
|
|
||||||
if templateRoot == "." || path.Base(templateRoot) != templateRoot {
|
|
||||||
return templateRoot, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := fs.Stat(builtinTemplates, path.Join("templates", templateRoot))
|
|
||||||
if err != nil {
|
|
||||||
// The given path doesn't appear to be using out built-in templates
|
|
||||||
return templateRoot, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// We have a built-in template with the same name as templateRoot!
|
|
||||||
// Now we need to make a fully copy of the builtin templates to a real file system
|
|
||||||
// since template.Parse() doesn't support embed.FS.
|
|
||||||
err = fs.WalkDir(builtinTemplates, "templates", func(path string, entry fs.DirEntry, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
targetPath := filepath.Join(tempDir, path)
|
|
||||||
if entry.IsDir() {
|
|
||||||
return os.Mkdir(targetPath, 0755)
|
|
||||||
} else {
|
|
||||||
content, err := fs.ReadFile(builtinTemplates, path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return os.WriteFile(targetPath, content, 0644)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return filepath.Join(tempDir, "templates", templateRoot), nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package template
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -19,6 +20,6 @@ func TestMaterializeForNonTemplateDirectory(t *testing.T) {
|
||||||
ctx := root.SetWorkspaceClient(context.Background(), w)
|
ctx := root.SetWorkspaceClient(context.Background(), w)
|
||||||
|
|
||||||
// Try to materialize a non-template directory.
|
// Try to materialize a non-template directory.
|
||||||
err = Materialize(ctx, "", tmpDir, "")
|
err = Materialize(ctx, "", os.DirFS(tmpDir), "")
|
||||||
assert.EqualError(t, err, fmt.Sprintf("not a bundle template: expected to find a template schema file at %s", filepath.Join(tmpDir, schemaFileName)))
|
assert.EqualError(t, err, fmt.Sprintf("not a bundle template: expected to find a template schema file at %s", filepath.Join(tmpDir, schemaFileName)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,12 @@ import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/filer"
|
|
||||||
"github.com/databricks/cli/libs/log"
|
"github.com/databricks/cli/libs/log"
|
||||||
"github.com/databricks/databricks-sdk-go/logger"
|
"github.com/databricks/databricks-sdk-go/logger"
|
||||||
)
|
)
|
||||||
|
@ -52,32 +50,43 @@ type renderer struct {
|
||||||
// do not match any glob patterns from this list
|
// do not match any glob patterns from this list
|
||||||
skipPatterns []string
|
skipPatterns []string
|
||||||
|
|
||||||
// Filer rooted at template root. The file tree from this root is walked to
|
// [fs.FS] for the template root. The file tree from this root is walked to
|
||||||
// generate the project
|
// generate the project
|
||||||
templateFiler filer.Filer
|
templateRoot fs.FS
|
||||||
|
|
||||||
// Root directory for the project instantiated from the template
|
// Root directory for the project instantiated from the template
|
||||||
instanceRoot string
|
instanceRoot string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRenderer(ctx context.Context, config map[string]any, helpers template.FuncMap, templateRoot, libraryRoot, instanceRoot string) (*renderer, error) {
|
func newRenderer(
|
||||||
|
ctx context.Context,
|
||||||
|
config map[string]any,
|
||||||
|
helpers template.FuncMap,
|
||||||
|
templateFS fs.FS,
|
||||||
|
templateDir string,
|
||||||
|
libraryDir string,
|
||||||
|
instanceRoot string,
|
||||||
|
) (*renderer, error) {
|
||||||
// Initialize new template, with helper functions loaded
|
// Initialize new template, with helper functions loaded
|
||||||
tmpl := template.New("").Funcs(helpers)
|
tmpl := template.New("").Funcs(helpers)
|
||||||
|
|
||||||
// Load user defined associated templates from the library root
|
// Find user-defined templates in the library directory
|
||||||
libraryGlob := filepath.Join(libraryRoot, "*")
|
matches, err := fs.Glob(templateFS, path.Join(libraryDir, "*"))
|
||||||
matches, err := filepath.Glob(libraryGlob)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse user-defined templates.
|
||||||
|
// Note: we do not call [ParseFS] with the glob directly because
|
||||||
|
// it returns an error if no files match the pattern.
|
||||||
if len(matches) != 0 {
|
if len(matches) != 0 {
|
||||||
tmpl, err = tmpl.ParseFiles(matches...)
|
tmpl, err = tmpl.ParseFS(templateFS, matches...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
templateFiler, err := filer.NewLocalClient(templateRoot)
|
fsys, err := fs.Sub(templateFS, path.Clean(templateDir))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -85,13 +94,13 @@ func newRenderer(ctx context.Context, config map[string]any, helpers template.Fu
|
||||||
ctx = log.NewContext(ctx, log.GetLogger(ctx).With("action", "initialize-template"))
|
ctx = log.NewContext(ctx, log.GetLogger(ctx).With("action", "initialize-template"))
|
||||||
|
|
||||||
return &renderer{
|
return &renderer{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
config: config,
|
config: config,
|
||||||
baseTemplate: tmpl,
|
baseTemplate: tmpl,
|
||||||
files: make([]file, 0),
|
files: make([]file, 0),
|
||||||
skipPatterns: make([]string, 0),
|
skipPatterns: make([]string, 0),
|
||||||
templateFiler: templateFiler,
|
templateRoot: fsys,
|
||||||
instanceRoot: instanceRoot,
|
instanceRoot: instanceRoot,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +150,7 @@ func (r *renderer) executeTemplate(templateDefinition string) (string, error) {
|
||||||
|
|
||||||
func (r *renderer) computeFile(relPathTemplate string) (file, error) {
|
func (r *renderer) computeFile(relPathTemplate string) (file, error) {
|
||||||
// read file permissions
|
// read file permissions
|
||||||
info, err := r.templateFiler.Stat(r.ctx, relPathTemplate)
|
info, err := fs.Stat(r.templateRoot, relPathTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -161,10 +170,10 @@ func (r *renderer) computeFile(relPathTemplate string) (file, error) {
|
||||||
root: r.instanceRoot,
|
root: r.instanceRoot,
|
||||||
relPath: relPath,
|
relPath: relPath,
|
||||||
},
|
},
|
||||||
perm: perm,
|
perm: perm,
|
||||||
ctx: r.ctx,
|
ctx: r.ctx,
|
||||||
srcPath: relPathTemplate,
|
srcFS: r.templateRoot,
|
||||||
srcFiler: r.templateFiler,
|
srcPath: relPathTemplate,
|
||||||
}, nil
|
}, nil
|
||||||
} else {
|
} else {
|
||||||
// Trim the .tmpl suffix from file name, if specified in the template
|
// Trim the .tmpl suffix from file name, if specified in the template
|
||||||
|
@ -173,7 +182,7 @@ func (r *renderer) computeFile(relPathTemplate string) (file, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// read template file's content
|
// read template file's content
|
||||||
templateReader, err := r.templateFiler.Read(r.ctx, relPathTemplate)
|
templateReader, err := r.templateRoot.Open(relPathTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -263,7 +272,7 @@ func (r *renderer) walk() error {
|
||||||
//
|
//
|
||||||
// 2. For directories: They are appended to a slice, which acts as a queue
|
// 2. For directories: They are appended to a slice, which acts as a queue
|
||||||
// allowing BFS traversal of the template file tree
|
// allowing BFS traversal of the template file tree
|
||||||
entries, err := r.templateFiler.ReadDir(r.ctx, currentDirectory)
|
entries, err := fs.ReadDir(r.templateRoot, currentDirectory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@ package template
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -41,9 +41,8 @@ func assertFilePermissions(t *testing.T, path string, perm fs.FileMode) {
|
||||||
func assertBuiltinTemplateValid(t *testing.T, template string, settings map[string]any, target string, isServicePrincipal bool, build bool, tempDir string) {
|
func assertBuiltinTemplateValid(t *testing.T, template string, settings map[string]any, target string, isServicePrincipal bool, build bool, tempDir string) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
templatePath, err := prepareBuiltinTemplates(template, tempDir)
|
templateFS, err := fs.Sub(builtinTemplates, path.Join("templates", template))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
libraryPath := filepath.Join(templatePath, "library")
|
|
||||||
|
|
||||||
w := &databricks.WorkspaceClient{
|
w := &databricks.WorkspaceClient{
|
||||||
Config: &workspaceConfig.Config{Host: "https://myhost.com"},
|
Config: &workspaceConfig.Config{Host: "https://myhost.com"},
|
||||||
|
@ -58,7 +57,7 @@ func assertBuiltinTemplateValid(t *testing.T, template string, settings map[stri
|
||||||
ctx = root.SetWorkspaceClient(ctx, w)
|
ctx = root.SetWorkspaceClient(ctx, w)
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
|
|
||||||
renderer, err := newRenderer(ctx, settings, helpers, templatePath, libraryPath, tempDir)
|
renderer, err := newRenderer(ctx, settings, helpers, templateFS, templateDirName, libraryDirName, tempDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Evaluate template
|
// Evaluate template
|
||||||
|
@ -67,7 +66,7 @@ func assertBuiltinTemplateValid(t *testing.T, template string, settings map[stri
|
||||||
err = renderer.persistToDisk()
|
err = renderer.persistToDisk()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
b, err := bundle.Load(ctx, filepath.Join(tempDir, "template", "my_project"))
|
b, err := bundle.Load(ctx, filepath.Join(tempDir, "my_project"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
diags := bundle.Apply(ctx, b, phases.LoadNamedTarget(target))
|
diags := bundle.Apply(ctx, b, phases.LoadNamedTarget(target))
|
||||||
require.NoError(t, diags.Error())
|
require.NoError(t, diags.Error())
|
||||||
|
@ -96,18 +95,6 @@ func assertBuiltinTemplateValid(t *testing.T, template string, settings map[stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrepareBuiltInTemplatesWithRelativePaths(t *testing.T) {
|
|
||||||
// CWD should not be resolved as a built in template
|
|
||||||
dir, err := prepareBuiltinTemplates(".", t.TempDir())
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, ".", dir)
|
|
||||||
|
|
||||||
// relative path should not be resolved as a built in template
|
|
||||||
dir, err = prepareBuiltinTemplates("./default-python", t.TempDir())
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, "./default-python", dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuiltinPythonTemplateValid(t *testing.T) {
|
func TestBuiltinPythonTemplateValid(t *testing.T) {
|
||||||
// Test option combinations
|
// Test option combinations
|
||||||
options := []string{"yes", "no"}
|
options := []string{"yes", "no"}
|
||||||
|
@ -194,7 +181,7 @@ func TestRendererWithAssociatedTemplateInLibrary(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx = root.SetWorkspaceClient(ctx, nil)
|
ctx = root.SetWorkspaceClient(ctx, nil)
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/email/template", "./testdata/email/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/email/template", "./testdata/email/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -381,7 +368,7 @@ func TestRendererWalk(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/walk/template", "./testdata/walk/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/walk/template", "./testdata/walk/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -392,18 +379,9 @@ func TestRendererWalk(t *testing.T) {
|
||||||
if f.DstPath().relPath != path {
|
if f.DstPath().relPath != path {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch v := f.(type) {
|
b, err := f.contents()
|
||||||
case *inMemoryFile:
|
require.NoError(t, err)
|
||||||
return strings.Trim(string(v.content), "\r\n")
|
return strings.Trim(string(b), "\r\n")
|
||||||
case *copyFile:
|
|
||||||
r, err := r.templateFiler.Read(context.Background(), v.srcPath)
|
|
||||||
require.NoError(t, err)
|
|
||||||
b, err := io.ReadAll(r)
|
|
||||||
require.NoError(t, err)
|
|
||||||
return strings.Trim(string(b), "\r\n")
|
|
||||||
default:
|
|
||||||
require.FailNow(t, "execution should not reach here")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
require.FailNow(t, "file is absent: "+path)
|
require.FailNow(t, "file is absent: "+path)
|
||||||
return ""
|
return ""
|
||||||
|
@ -422,7 +400,7 @@ func TestRendererFailFunction(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/fail/template", "./testdata/fail/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/fail/template", "./testdata/fail/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -435,7 +413,7 @@ func TestRendererSkipsDirsEagerly(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/skip-dir-eagerly/template", "./testdata/skip-dir-eagerly/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/skip-dir-eagerly/template", "./testdata/skip-dir-eagerly/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -452,7 +430,7 @@ func TestRendererSkipAllFilesInCurrentDirectory(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/skip-all-files-in-cwd/template", "./testdata/skip-all-files-in-cwd/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/skip-all-files-in-cwd/template", "./testdata/skip-all-files-in-cwd/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -475,7 +453,7 @@ func TestRendererSkipPatternsAreRelativeToFileDirectory(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/skip-is-relative/template", "./testdata/skip-is-relative/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/skip-is-relative/template", "./testdata/skip-is-relative/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -493,7 +471,7 @@ func TestRendererSkip(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/skip/template", "./testdata/skip/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/skip/template", "./testdata/skip/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -525,7 +503,7 @@ func TestRendererReadsPermissionsBits(t *testing.T) {
|
||||||
ctx = root.SetWorkspaceClient(ctx, nil)
|
ctx = root.SetWorkspaceClient(ctx, nil)
|
||||||
|
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/executable-bit-read/template", "./testdata/executable-bit-read/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/executable-bit-read/template", "./testdata/executable-bit-read/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -615,7 +593,7 @@ func TestRendererNonTemplatesAreCreatedAsCopyFiles(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
helpers := loadHelpers(ctx)
|
helpers := loadHelpers(ctx)
|
||||||
r, err := newRenderer(ctx, nil, helpers, "./testdata/copy-file-walk/template", "./testdata/copy-file-walk/library", tmpDir)
|
r, err := newRenderer(ctx, nil, helpers, os.DirFS("."), "./testdata/copy-file-walk/template", "./testdata/copy-file-walk/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -635,7 +613,7 @@ func TestRendererFileTreeRendering(t *testing.T) {
|
||||||
r, err := newRenderer(ctx, map[string]any{
|
r, err := newRenderer(ctx, map[string]any{
|
||||||
"dir_name": "my_directory",
|
"dir_name": "my_directory",
|
||||||
"file_name": "my_file",
|
"file_name": "my_file",
|
||||||
}, helpers, "./testdata/file-tree-rendering/template", "./testdata/file-tree-rendering/library", tmpDir)
|
}, helpers, os.DirFS("."), "./testdata/file-tree-rendering/template", "./testdata/file-tree-rendering/library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
@ -668,7 +646,7 @@ func TestRendererSubTemplateInPath(t *testing.T) {
|
||||||
testutil.Touch(t, filepath.Join(templateDir, "template/{{template `dir_name`}}/{{template `file_name`}}"))
|
testutil.Touch(t, filepath.Join(templateDir, "template/{{template `dir_name`}}/{{template `file_name`}}"))
|
||||||
|
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
r, err := newRenderer(ctx, nil, nil, filepath.Join(templateDir, "template"), filepath.Join(templateDir, "library"), tmpDir)
|
r, err := newRenderer(ctx, nil, nil, os.DirFS(templateDir), "template", "library", tmpDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = r.walk()
|
err = r.walk()
|
||||||
|
|
Loading…
Reference in New Issue