diff --git a/libs/template/resolver.go b/libs/template/resolver.go index 16b2e692b..5afc6a237 100644 --- a/libs/template/resolver.go +++ b/libs/template/resolver.go @@ -3,6 +3,7 @@ package template import ( "context" "errors" + "fmt" "github.com/databricks/cli/libs/git" ) @@ -37,7 +38,7 @@ var ErrCustomSelected = errors.New("custom template selected") // Prompts the user if needed. func (r Resolver) Resolve(ctx context.Context) (*Template, error) { if r.Tag != "" && r.Branch != "" { - return nil, errors.New("only one of --tag or --branch can be specified") + return nil, fmt.Errorf("only one of --tag or --branch can be specified") } // Git ref to use for template initialization diff --git a/libs/template/resolver_test.go b/libs/template/resolver_test.go index c94548d59..d057e7880 100644 --- a/libs/template/resolver_test.go +++ b/libs/template/resolver_test.go @@ -66,7 +66,7 @@ func TestTemplateResolverForDefaultTemplates(t *testing.T) { assert.Equal(t, "/config/file", tmpl.Writer.(*writerWithTelemetry).configPath) } -func TestTemplateResolverForCustomTemplate(t *testing.T) { +func TestTemplateResolverForCustomUrl(t *testing.T) { r := Resolver{ TemplatePathOrUrl: "https://www.example.com/abc", Tag: "tag", @@ -77,6 +77,8 @@ func TestTemplateResolverForCustomTemplate(t *testing.T) { tmpl, err := r.Resolve(context.Background()) require.NoError(t, err) + assert.Equal(t, Custom, tmpl.name) + // Assert reader configuration assert.Equal(t, "https://www.example.com/abc", tmpl.Reader.(*gitReader).gitUrl) assert.Equal(t, "tag", tmpl.Reader.(*gitReader).ref) @@ -85,3 +87,21 @@ func TestTemplateResolverForCustomTemplate(t *testing.T) { // Assert writer configuration assert.Equal(t, "/config/file", tmpl.Writer.(*defaultWriter).configPath) } + +func TestTemplateResolverForCustomPath(t *testing.T) { + r := Resolver{ + TemplatePathOrUrl: "/custom/path", + ConfigFile: "/config/file", + } + + tmpl, err := r.Resolve(context.Background()) + require.NoError(t, err) + + assert.Equal(t, Custom, tmpl.name,) + + // Assert reader configuration + assert.Equal(t, "/custom/path", tmpl.Reader.(*localReader).path) + + // Assert writer configuration + assert.Equal(t, "/config/file", tmpl.Writer.(*defaultWriter).configPath) +}