cleanup code

This commit is contained in:
Shreyas Goenka 2024-12-27 12:19:42 +05:30
parent a3fbdd33a5
commit ecb977f4ed
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
5 changed files with 50 additions and 17 deletions

View File

@ -235,12 +235,11 @@ See https://docs.databricks.com/en/dev-tools/bundles/templates.html for more inf
return nil
}
// If templatePath refers to a native template, store it's name in a new
// variable.
nt := getNativeTemplateByName(templatePath)
templateName := "custom"
isTemplateDatabricksOwned := false
if nt != nil {
// If the template is a native template, set it's value.
templateName = templatePath
// if we have a Git URL for the native template, expand templatePath

View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"slices"
"time"
"github.com/databricks/cli/libs/log"
@ -61,19 +62,6 @@ func Flush(ctx context.Context, apiClient DatabricksApiClient) {
return
}
// We pass the API client as an arg to mock it in unit tests.
// TODO: Cleanup and remove this section.
// if apiClient == nil {
// var err error
// // Create API client to make the the telemetry API call.
// apiClient, err = client.New(root.WorkspaceClient(ctx).Config)
// if err != nil {
// log.Debugf(ctx, "error creating API client for telemetry: %v", err)
// return
// }
// }
resp := &ResponseBody{}
for {
select {

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io/fs"
"slices"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/jsonschema"
@ -279,10 +280,17 @@ func (c *config) validate() error {
func (c *config) enumValues() map[string]string {
res := map[string]string{}
for k, p := range c.schema.Properties {
if p.Type != jsonschema.StringType {
continue
}
if p.Enum == nil {
continue
}
res[k] = c.values[k].(string)
v := c.values[k]
if slices.Contains(p.Enum, v) {
res[k] = v.(string)
}
}
return res
}

View File

@ -564,3 +564,42 @@ func TestPromptIsSkippedAnyOf(t *testing.T) {
assert.True(t, skip)
assert.Equal(t, "hello-world", c.values["xyz"])
}
func TestConfigEnumValues(t *testing.T) {
c := &config{
schema: &jsonschema.Schema{
Properties: map[string]*jsonschema.Schema{
"a": {
Type: jsonschema.StringType,
},
"b": {
Type: jsonschema.BooleanType,
},
"c": {
Type: jsonschema.StringType,
Enum: []any{"v1", "v2"},
},
"d": {
Type: jsonschema.StringType,
Enum: []any{"v3", "v4"},
},
"e": {
Type: jsonschema.StringType,
Enum: []any{"v5", "v6"},
},
},
},
values: map[string]any{
"a": "w1",
"b": false,
"c": "v1",
"d": "v3",
"e": "v7",
},
}
assert.Equal(t, map[string]string{
"c": "v1",
"d": "v3",
}, c.enumValues())
}

View File

@ -29,7 +29,6 @@ type TemplateOpts struct {
IsDatabricksOwned bool
// Name of the template. For non-Databricks owned templates, this is set to
// custom.
// TODO: move this enum to the template package.
Name string
}