more test

This commit is contained in:
Shreyas Goenka 2025-01-06 18:38:22 +05:30
parent 0a68fb34f9
commit 8202aafc78
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 23 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package template
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"github.com/databricks/cli/libs/git" "github.com/databricks/cli/libs/git"
) )
@ -37,7 +38,7 @@ var ErrCustomSelected = errors.New("custom template selected")
// Prompts the user if needed. // Prompts the user if needed.
func (r Resolver) Resolve(ctx context.Context) (*Template, error) { func (r Resolver) Resolve(ctx context.Context) (*Template, error) {
if r.Tag != "" && r.Branch != "" { 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 // Git ref to use for template initialization

View File

@ -66,7 +66,7 @@ func TestTemplateResolverForDefaultTemplates(t *testing.T) {
assert.Equal(t, "/config/file", tmpl.Writer.(*writerWithTelemetry).configPath) assert.Equal(t, "/config/file", tmpl.Writer.(*writerWithTelemetry).configPath)
} }
func TestTemplateResolverForCustomTemplate(t *testing.T) { func TestTemplateResolverForCustomUrl(t *testing.T) {
r := Resolver{ r := Resolver{
TemplatePathOrUrl: "https://www.example.com/abc", TemplatePathOrUrl: "https://www.example.com/abc",
Tag: "tag", Tag: "tag",
@ -77,6 +77,8 @@ func TestTemplateResolverForCustomTemplate(t *testing.T) {
tmpl, err := r.Resolve(context.Background()) tmpl, err := r.Resolve(context.Background())
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, Custom, tmpl.name)
// Assert reader configuration // Assert reader configuration
assert.Equal(t, "https://www.example.com/abc", tmpl.Reader.(*gitReader).gitUrl) assert.Equal(t, "https://www.example.com/abc", tmpl.Reader.(*gitReader).gitUrl)
assert.Equal(t, "tag", tmpl.Reader.(*gitReader).ref) assert.Equal(t, "tag", tmpl.Reader.(*gitReader).ref)
@ -85,3 +87,21 @@ func TestTemplateResolverForCustomTemplate(t *testing.T) {
// Assert writer configuration // Assert writer configuration
assert.Equal(t, "/config/file", tmpl.Writer.(*defaultWriter).configPath) 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)
}