databricks-cli/bundle/config/mutator/initialize_urls_test.go

131 lines
4.0 KiB
Go
Raw Normal View History

2024-08-24 18:48:36 +00:00
package mutator
import (
"testing"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/databricks-sdk-go/service/catalog"
2024-10-17 14:45:18 +00:00
"github.com/databricks/databricks-sdk-go/service/compute"
2024-08-24 18:48:36 +00:00
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/databricks/databricks-sdk-go/service/ml"
"github.com/databricks/databricks-sdk-go/service/pipelines"
"github.com/databricks/databricks-sdk-go/service/serving"
"github.com/stretchr/testify/require"
)
2024-08-29 14:45:07 +00:00
func TestInitializeURLs(t *testing.T) {
2024-08-24 18:48:36 +00:00
b := &bundle.Bundle{
Config: config.Root{
Workspace: config.Workspace{
Host: "https://mycompany.databricks.com/",
},
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"job1": {
ID: "1",
JobSettings: &jobs.JobSettings{Name: "job1"},
},
},
Pipelines: map[string]*resources.Pipeline{
"pipeline1": {
ID: "3",
PipelineSpec: &pipelines.PipelineSpec{Name: "pipeline1"},
},
},
Experiments: map[string]*resources.MlflowExperiment{
"experiment1": {
ID: "4",
Experiment: &ml.Experiment{Name: "experiment1"},
},
},
Models: map[string]*resources.MlflowModel{
"model1": {
2024-10-17 15:17:17 +00:00
ID: "a model uses its name for identifier",
2024-08-24 18:48:36 +00:00
Model: &ml.Model{Name: "model1"},
},
},
ModelServingEndpoints: map[string]*resources.ModelServingEndpoint{
"servingendpoint1": {
2024-10-17 15:17:17 +00:00
ID: "my_serving_endpoint",
2024-08-24 18:48:36 +00:00
CreateServingEndpoint: &serving.CreateServingEndpoint{
Name: "my_serving_endpoint",
},
},
},
RegisteredModels: map[string]*resources.RegisteredModel{
"registeredmodel1": {
ID: "8",
CreateRegisteredModelRequest: &catalog.CreateRegisteredModelRequest{
Name: "my_registered_model",
},
},
},
QualityMonitors: map[string]*resources.QualityMonitor{
"qualityMonitor1": {
CreateMonitor: &catalog.CreateMonitor{
TableName: "catalog.schema.qualityMonitor1",
},
},
},
Schemas: map[string]*resources.Schema{
"schema1": {
ID: "catalog.schema",
CreateSchema: &catalog.CreateSchema{
Name: "schema",
},
},
},
2024-10-17 14:45:18 +00:00
Clusters: map[string]*resources.Cluster{
"cluster1": {
ID: "1017-103929-vlr7jzcf",
ClusterSpec: &compute.ClusterSpec{
ClusterName: "cluster1",
},
},
},
2024-08-24 18:48:36 +00:00
},
},
}
expectedURLs := map[string]string{
"job1": "https://mycompany.databricks.com/jobs/1?o=123456",
"pipeline1": "https://mycompany.databricks.com/pipelines/3?o=123456",
"experiment1": "https://mycompany.databricks.com/ml/experiments/4?o=123456",
2024-10-17 15:17:17 +00:00
"model1": "https://mycompany.databricks.com/ml/models/a model uses its name for identifier?o=123456",
2024-08-24 18:48:36 +00:00
"servingendpoint1": "https://mycompany.databricks.com/ml/endpoints/my_serving_endpoint?o=123456",
"registeredmodel1": "https://mycompany.databricks.com/explore/data/models/8?o=123456",
"qualityMonitor1": "https://mycompany.databricks.com/explore/data/catalog/schema/qualityMonitor1?o=123456",
"schema1": "https://mycompany.databricks.com/explore/data/catalog/schema?o=123456",
2024-10-17 14:45:18 +00:00
"cluster1": "https://mycompany.databricks.com/compute/clusters/1017-103929-vlr7jzcf?o=123456",
2024-08-24 18:48:36 +00:00
}
2024-10-05 03:43:00 +00:00
initializeForWorkspace(b, "123456", "https://mycompany.databricks.com/")
2024-08-24 18:48:36 +00:00
2024-10-17 14:39:17 +00:00
for _, group := range b.Config.Resources.AllResources() {
for key, r := range group.Resources {
2024-08-24 18:48:36 +00:00
require.Equal(t, expectedURLs[key], r.GetURL(), "Unexpected URL for "+key)
}
}
}
2024-10-11 12:43:36 +00:00
func TestInitializeURLsWithoutOrgId(t *testing.T) {
2024-08-24 18:48:36 +00:00
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"job1": {
ID: "1",
JobSettings: &jobs.JobSettings{Name: "job1"},
},
},
},
},
}
2024-10-05 03:43:00 +00:00
initializeForWorkspace(b, "123456", "https://adb-123456.azuredatabricks.net/")
2024-08-24 18:48:36 +00:00
require.Equal(t, "https://adb-123456.azuredatabricks.net/jobs/1", b.Config.Resources.Jobs["job1"].URL)
}