99 "github.com/databricks/cli/bundle"
1010 "github.com/databricks/cli/bundle/config"
1111 "github.com/databricks/cli/bundle/config/resources"
12+ "github.com/databricks/cli/libs/tags"
13+ sdkconfig "github.com/databricks/databricks-sdk-go/config"
1214 "github.com/databricks/databricks-sdk-go/service/iam"
1315 "github.com/databricks/databricks-sdk-go/service/jobs"
1416 "github.com/databricks/databricks-sdk-go/service/ml"
@@ -59,6 +61,10 @@ func mockBundle(mode config.Mode) *bundle.Bundle {
5961 },
6062 },
6163 },
64+ // Use AWS implementation for testing.
65+ Tagging : tags .ForCloud (& sdkconfig.Config {
66+ Host : "https://company.cloud.databricks.com" ,
67+ }),
6268 }
6369}
6470
@@ -68,14 +74,71 @@ func TestProcessTargetModeDevelopment(t *testing.T) {
6874 m := ProcessTargetMode ()
6975 err := m .Apply (context .Background (), bundle )
7076 require .NoError (t , err )
77+
78+ // Job 1
7179 assert .Equal (t , "[dev lennart] job1" , bundle .Config .Resources .Jobs ["job1" ].Name )
80+ assert .Equal (t , bundle .Config .Resources .Jobs ["job1" ].Tags ["dev" ], "lennart" )
81+
82+ // Pipeline 1
7283 assert .Equal (t , "[dev lennart] pipeline1" , bundle .Config .Resources .Pipelines ["pipeline1" ].Name )
84+ assert .True (t , bundle .Config .Resources .Pipelines ["pipeline1" ].PipelineSpec .Development )
85+
86+ // Experiment 1
7387 assert .
Equal (
t ,
"/Users/[email protected] /[dev lennart] experiment1" ,
bundle .
Config .
Resources .
Experiments [
"experiment1" ].
Name )
88+ assert .Contains (t , bundle .Config .Resources .Experiments ["experiment1" ].Experiment .Tags , ml.ExperimentTag {Key : "dev" , Value : "lennart" })
89+
90+ // Experiment 2
7491 assert .Equal (t , "[dev lennart] experiment2" , bundle .Config .Resources .Experiments ["experiment2" ].Name )
92+ assert .Contains (t , bundle .Config .Resources .Experiments ["experiment2" ].Experiment .Tags , ml.ExperimentTag {Key : "dev" , Value : "lennart" })
93+
94+ // Model 1
7595 assert .Equal (t , "[dev lennart] model1" , bundle .Config .Resources .Models ["model1" ].Name )
96+
97+ // Model serving endpoint 1
7698 assert .Equal (t , "dev_lennart_servingendpoint1" , bundle .Config .Resources .ModelServingEndpoints ["servingendpoint1" ].Name )
7799 assert .Equal (t , "dev" , bundle .Config .Resources .Experiments ["experiment1" ].Experiment .Tags [0 ].Key )
78- assert .True (t , bundle .Config .Resources .Pipelines ["pipeline1" ].PipelineSpec .Development )
100+ }
101+
102+ func TestProcessTargetModeDevelopmentTagNormalizationForAws (t * testing.T ) {
103+ bundle := mockBundle (config .Development )
104+ bundle .Tagging = tags .ForCloud (& sdkconfig.Config {
105+ Host : "https://dbc-XXXXXXXX-YYYY.cloud.databricks.com/" ,
106+ })
107+
108+ bundle .Config .Workspace .CurrentUser .ShortName = "Héllö wörld?!"
109+ err := ProcessTargetMode ().Apply (context .Background (), bundle )
110+ require .NoError (t , err )
111+
112+ // Assert that tag normalization took place.
113+ assert .Equal (t , "Hello world__" , bundle .Config .Resources .Jobs ["job1" ].Tags ["dev" ])
114+ }
115+
116+ func TestProcessTargetModeDevelopmentTagNormalizationForAzure (t * testing.T ) {
117+ bundle := mockBundle (config .Development )
118+ bundle .Tagging = tags .ForCloud (& sdkconfig.Config {
119+ Host : "https://adb-xxx.y.azuredatabricks.net/" ,
120+ })
121+
122+ bundle .Config .Workspace .CurrentUser .ShortName = "Héllö wörld?!"
123+ err := ProcessTargetMode ().Apply (context .Background (), bundle )
124+ require .NoError (t , err )
125+
126+ // Assert that tag normalization took place (Azure allows more characters than AWS).
127+ assert .Equal (t , "Héllö wörld?!" , bundle .Config .Resources .Jobs ["job1" ].Tags ["dev" ])
128+ }
129+
130+ func TestProcessTargetModeDevelopmentTagNormalizationForGcp (t * testing.T ) {
131+ bundle := mockBundle (config .Development )
132+ bundle .Tagging = tags .ForCloud (& sdkconfig.Config {
133+ Host : "https://123.4.gcp.databricks.com/" ,
134+ })
135+
136+ bundle .Config .Workspace .CurrentUser .ShortName = "Héllö wörld?!"
137+ err := ProcessTargetMode ().Apply (context .Background (), bundle )
138+ require .NoError (t , err )
139+
140+ // Assert that tag normalization took place.
141+ assert .Equal (t , "Hello_world" , bundle .Config .Resources .Jobs ["job1" ].Tags ["dev" ])
79142}
80143
81144func TestProcessTargetModeDefault (t * testing.T ) {
0 commit comments