@@ -47,121 +47,86 @@ func initUnifiedHostAccountEnv(t *testing.T) {
4747 }
4848}
4949
50- func unifiedHostCreateJobTest (t * testing.T ) {
50+ func initUnifiedHostWorkspaceEnv (t * testing.T ) {
51+ LoadWorkspaceEnv (t )
5152 unifiedHost := os .Getenv ("UNIFIED_HOST" )
52- workspaceID := GetEnvOrSkipTest (t , "TEST_WORKSPACE_ID" )
53- jobName := "tf-unified-" + RandomName () + "-job-1"
53+ if unifiedHost == "" {
54+ Skipf (t )("UNIFIED_HOST environment variable is missing" )
55+ }
56+ }
5457
55- run (t , []Step {
56- {
57- Template : `
58- resource "databricks_job" "j1" {
59- name = "` + jobName + `"
60- provider_config {
61- workspace_id = ` + workspaceID + `
62- }
63- task {
64- task_key = "check"
65- condition_task {
66- left = "true"
67- op = "EQUAL_TO"
68- right = "true"
69- }
70- }
58+ // createJobWithProviderConfig is a shared test helper that creates a job with
59+ // provider_config { workspace_id } and verifies it. If providerFactories is nil,
60+ // it uses the default provider factories.
61+ func createJobWithProviderConfig (t * testing.T , workspaceID string , providerFactories map [string ]func () (tfprotov6.ProviderServer , error )) {
62+ jobName := "tf-" + RandomName () + "-job-1"
63+
64+ step := Step {
65+ Template : `
66+ resource "databricks_job" "j1" {
67+ name = "` + jobName + `"
68+ provider_config {
69+ workspace_id = ` + workspaceID + `
7170 }
72- ` ,
73- ProtoV6ProviderFactories : unifiedHostProviderFactories (unifiedHost ),
74- Check : ResourceCheck ("databricks_job.j1" , func (ctx context.Context , client * common.DatabricksClient , id string ) error {
75- w , err := client .GetWorkspaceClientForUnifiedProvider (ctx , workspaceID )
76- if err != nil {
77- return err
78- }
79- jobID , err := strconv .ParseInt (id , 10 , 64 )
80- if err != nil {
81- return err
82- }
83- res , err := w .Jobs .Get (ctx , jobs.GetJobRequest {JobId : jobID })
84- if err != nil {
85- return err
86- }
87- if res .Settings .Name != jobName {
88- return fmt .Errorf ("expected job name %q, got %q" , jobName , res .Settings .Name )
71+ task {
72+ task_key = "check"
73+ condition_task {
74+ left = "true"
75+ op = "EQUAL_TO"
76+ right = "true"
8977 }
90- return nil
91- }),
92- },
93- })
78+ }
79+ }
80+ ` ,
81+ Check : ResourceCheck ("databricks_job.j1" , func (ctx context.Context , client * common.DatabricksClient , id string ) error {
82+ w , err := client .GetWorkspaceClientForUnifiedProvider (ctx , workspaceID )
83+ if err != nil {
84+ return err
85+ }
86+ jobID , err := strconv .ParseInt (id , 10 , 64 )
87+ if err != nil {
88+ return err
89+ }
90+ res , err := w .Jobs .Get (ctx , jobs.GetJobRequest {JobId : jobID })
91+ if err != nil {
92+ return err
93+ }
94+ if res .Settings .Name != jobName {
95+ return fmt .Errorf ("expected job name %q, got %q" , jobName , res .Settings .Name )
96+ }
97+ return nil
98+ }),
99+ }
100+ if providerFactories != nil {
101+ step .ProtoV6ProviderFactories = providerFactories
102+ }
103+ run (t , []Step {step })
94104}
95105
96106func TestMwsAccUnifiedHostCreateJobs (t * testing.T ) {
97107 initUnifiedHostAccountEnv (t )
98- unifiedHostCreateJobTest (t )
108+ unifiedHost := os .Getenv ("UNIFIED_HOST" )
109+ workspaceID := GetEnvOrSkipTest (t , "TEST_WORKSPACE_ID" )
110+ createJobWithProviderConfig (t , workspaceID , unifiedHostProviderFactories (unifiedHost ))
99111}
100112
101- func unifiedHostWorkspaceCreateJobTest (t * testing.T ) {
113+ func TestAccUnifiedHostWorkspaceCreateJobs (t * testing.T ) {
114+ initUnifiedHostWorkspaceEnv (t )
115+ if ! IsAzure (t ) {
116+ Skipf (t )("This test is only running on Azure until ACCOUNT_ID is exported in our workspace test environments" )
117+ }
102118 unifiedHost := os .Getenv ("UNIFIED_HOST" )
103119 ctx := context .Background ()
104120 w := databricks .Must (databricks .NewWorkspaceClient ())
105121 workspaceID , err := w .CurrentWorkspaceID (ctx )
106122 if err != nil {
107123 t .Fatalf ("failed to get current workspace ID: %s" , err )
108124 }
109- workspaceIDStr := strconv .FormatInt (workspaceID , 10 )
110- jobName := "tf-unified-ws-" + RandomName () + "-job-1"
111-
112- run (t , []Step {
113- {
114- Template : `
115- resource "databricks_job" "j1" {
116- name = "` + jobName + `"
117- provider_config {
118- workspace_id = ` + workspaceIDStr + `
119- }
120- task {
121- task_key = "check"
122- condition_task {
123- left = "true"
124- op = "EQUAL_TO"
125- right = "true"
126- }
127- }
128- }
129- ` ,
130- ProtoV6ProviderFactories : unifiedHostProviderFactories (unifiedHost ),
131- Check : ResourceCheck ("databricks_job.j1" , func (ctx context.Context , client * common.DatabricksClient , id string ) error {
132- w , err := client .WorkspaceClient ()
133- if err != nil {
134- return err
135- }
136- jobID , err := strconv .ParseInt (id , 10 , 64 )
137- if err != nil {
138- return err
139- }
140- res , err := w .Jobs .Get (ctx , jobs.GetJobRequest {JobId : jobID })
141- if err != nil {
142- return err
143- }
144- if res .Settings .Name != jobName {
145- return fmt .Errorf ("expected job name %q, got %q" , jobName , res .Settings .Name )
146- }
147- return nil
148- }),
149- },
150- })
151- }
152-
153- func initUnifiedHostWorkspaceEnv (t * testing.T ) {
154- LoadWorkspaceEnv (t )
155- unifiedHost := os .Getenv ("UNIFIED_HOST" )
156- if unifiedHost == "" {
157- Skipf (t )("UNIFIED_HOST environment variable is missing" )
158- }
125+ createJobWithProviderConfig (t , strconv .FormatInt (workspaceID , 10 ), unifiedHostProviderFactories (unifiedHost ))
159126}
160127
161- func TestAccUnifiedHostWorkspaceCreateJobs (t * testing.T ) {
162- initUnifiedHostWorkspaceEnv (t )
163- if ! IsAzure (t ) {
164- Skipf (t )("This test is only running on Azure until ACCOUNT_ID is exported in our workspace test environments" )
165- }
166- unifiedHostWorkspaceCreateJobTest (t )
128+ func TestMwsAccAccountHostCreateJobs (t * testing.T ) {
129+ LoadAccountEnv (t )
130+ workspaceID := GetEnvOrSkipTest (t , "TEST_WORKSPACE_ID" )
131+ createJobWithProviderConfig (t , workspaceID , nil )
167132}
0 commit comments