Skip to content

Commit c10a8fe

Browse files
authored
[Internal] Host Agnostic Test Fixtures (#5592)
## Changes Decouples provider tests from the Databricks Go SDK's `Config.HostType()` back-door, where `isTesting && AccountID != ""` causes `HostType()` to return `AccountHost` regardless of the configured `Host`. Tests previously relied on this shortcut by setting only `AccountID` and leaving `Host` empty. This PR makes every account-level test declare its Host explicitly, so the SDK can eventually drop the `isTesting` special-case without provider-test fallout. 1. **`qa/testing.go`** — `ResourceFixture` gains a `Host` field that threads into `config.Config.Host`. `MockAccountsApply` now reads `Host` from the mock account client's own config (`ma.AccountClient.Config.Host`) instead of hardcoding `https://accounts.cloud.databricks.com` — the test now owns the value. 2. **`exporter/importables_test.go`** — `importContextForAccountTestWithClient` no longer calls `client.Config.WithTesting()`. Exporter account tests no longer ride the SDK's `isTesting` shortcut. 3. **~20 `ResourceFixture` tests** (`catalog/`, `mws/`, `scim/`, `apps/`, `finops/`, `permissions/`, `tokens/`) — set `Host` explicitly where needed, or add `api = "account"` to HCL so the resource's own routing logic runs. Dead `Fixtures: []qa.HTTPFixture{}` entries removed from tests that made no HTTP calls. 4. **`exporter/impl_{billing,serverless,uc}_test.go`** — 29 callbacks now call `setupAwsAccountConfig(ma)` (or `setupAzureAccountConfig(ma)` for Azure-specific tests) at the top, matching the existing convention in `impl_mws_test.go` / `impl_oauth_test.go`. Replaces partial `Config = &config.Config{AccountID: ...}` inline blocks that silently relied on `WithTesting()` to fill in the Host. ### Storage credential conversion `TestStorageCredentialImportAccountLevel` converted from `HTTPFixture` to `MockAccountClientFunc` since the test exercises mock-client paths. ## Tests - `make fmt` ✅ - `make lint` ✅ - `make test` — 3084 tests pass, 0 failures - Tested by removing the isTesting check: #5593 NO_CHANGELOG=true
1 parent e8c7466 commit c10a8fe

28 files changed

Lines changed: 134 additions & 41 deletions

apps/resource_custom_app_integration_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func TestResourceCustomAppIntegrationCreate(t *testing.T) {
5151
},
5252
Create: true,
5353
AccountID: "account_id",
54+
Host: "https://accounts.cloud.databricks.com",
5455
HCL: `
5556
name = "custom_integration_name"
5657
redirect_urls = ["https://example.com"]
@@ -93,6 +94,7 @@ func TestResourceCustomAppIntegrationRead(t *testing.T) {
9394
Read: true,
9495
New: true,
9596
AccountID: "account_id",
97+
Host: "https://accounts.cloud.databricks.com",
9698
ID: "integration_id",
9799
}.ApplyAndExpectData(t, map[string]any{
98100
"name": "custom_integration_name",
@@ -158,6 +160,7 @@ func TestResourceCustomAppIntegrationUpdate(t *testing.T) {
158160
"token_access_policy.refresh_token_ttl_in_minutes": "30",
159161
},
160162
AccountID: "account_id",
163+
Host: "https://accounts.cloud.databricks.com",
161164
ID: "integration_id",
162165
}.ApplyAndExpectData(t, map[string]any{
163166
"name": "custom_integration_name",
@@ -172,6 +175,7 @@ func TestResourceCustomAppIntegrationDelete(t *testing.T) {
172175
},
173176
Resource: ResourceCustomAppIntegration(),
174177
AccountID: "account_id",
178+
Host: "https://accounts.cloud.databricks.com",
175179
Delete: true,
176180
ID: "integration_id",
177181
}.ApplyAndExpectData(t, nil)

catalog/data_metastore_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestMetastoreDataById(t *testing.T) {
2828
NonWritable: true,
2929
ID: "_",
3030
AccountID: "testaccount",
31+
Host: "https://accounts.cloud.databricks.com",
3132
HCL: `
3233
metastore_id = "abc"
3334
`,
@@ -47,6 +48,7 @@ func TestMetastoreDataErrorNoParams(t *testing.T) {
4748
NonWritable: true,
4849
ID: "_",
4950
AccountID: "_",
51+
Host: "https://accounts.cloud.databricks.com",
5052
}.ExpectError(t, "one of metastore_id, name or region must be provided")
5153
}
5254

@@ -57,6 +59,7 @@ func TestMetastoreDataErrorMultipleParams(t *testing.T) {
5759
NonWritable: true,
5860
ID: "_",
5961
AccountID: "_",
62+
Host: "https://accounts.cloud.databricks.com",
6063
HCL: `
6164
metastore_id = "abc"
6265
name = "abc"
@@ -96,6 +99,7 @@ func TestMetastoreByName(t *testing.T) {
9699
NonWritable: true,
97100
ID: "_",
98101
AccountID: "testaccount",
102+
Host: "https://accounts.cloud.databricks.com",
99103
HCL: `
100104
name = "xyz"
101105
`,
@@ -126,6 +130,7 @@ func TestMetastoreByRegion(t *testing.T) {
126130
NonWritable: true,
127131
ID: "_",
128132
AccountID: "testaccount",
133+
Host: "https://accounts.cloud.databricks.com",
129134
HCL: `
130135
region = "westus"
131136
`,
@@ -150,6 +155,7 @@ func TestMetastoreByNameNoData(t *testing.T) {
150155
NonWritable: true,
151156
ID: "_",
152157
AccountID: "testaccount",
158+
Host: "https://accounts.cloud.databricks.com",
153159
HCL: `
154160
name = "test"
155161
`,
@@ -167,6 +173,7 @@ func TestMetastoreByNameListError(t *testing.T) {
167173
NonWritable: true,
168174
ID: "_",
169175
AccountID: "testaccount",
176+
Host: "https://accounts.cloud.databricks.com",
170177
HCL: `
171178
name = "test"
172179
`,
@@ -197,6 +204,7 @@ func TestMetastoreByRegionMultipleEntries(t *testing.T) {
197204
NonWritable: true,
198205
ID: "_",
199206
AccountID: "testaccount",
207+
Host: "https://accounts.cloud.databricks.com",
200208
HCL: `
201209
region = "westus"
202210
`,

catalog/data_metastores_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestMetastoresDataContainsName(t *testing.T) {
3737
NonWritable: true,
3838
ID: "_",
3939
AccountID: "testaccount",
40+
Host: "https://accounts.cloud.databricks.com",
4041
}.ApplyAndExpectData(t, map[string]any{
4142
"ids": map[string]interface{}{"a": "abc", "b": "ded"},
4243
})
@@ -57,5 +58,6 @@ func TestMetastoresData_Error(t *testing.T) {
5758
NonWritable: true,
5859
ID: "_",
5960
AccountID: "_",
61+
Host: "https://accounts.cloud.databricks.com",
6062
}.ExpectError(t, "Bad request: unable to list metastores")
6163
}

catalog/resource_metastore_api_field_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func TestCreateMetastore_ApiFieldWorkspace(t *testing.T) {
7575
},
7676
Resource: ResourceMetastore(),
7777
AccountID: "100",
78+
Host: "https://accounts.cloud.databricks.com",
7879
Create: true,
7980
HCL: `
8081
name = "a"

catalog/resource_metastore_assignment_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func TestMetastoreAssignmentAccount_Create(t *testing.T) {
9292
HCL: `
9393
workspace_id = 123
9494
metastore_id = "a"
95+
api = "account"
9596
`,
9697
}.ApplyNoError(t)
9798
}
@@ -132,6 +133,7 @@ func TestMetastoreAssignmentAccount_Update(t *testing.T) {
132133
HCL: `
133134
workspace_id = 123
134135
metastore_id = "b"
136+
api = "account"
135137
`,
136138
}.ApplyNoError(t)
137139
}
@@ -172,6 +174,7 @@ func TestMetastoreAssignmentWorskpace_Update(t *testing.T) {
172174
HCL: `
173175
workspace_id = 124
174176
metastore_id = "a"
177+
api = "account"
175178
`,
176179
}.ApplyNoError(t)
177180
}

catalog/resource_metastore_data_access_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func TestCreateAccountDacWithAws(t *testing.T) {
236236
metastore_id = "abc"
237237
name = "bcd"
238238
is_default = true
239+
api = "account"
239240
aws_iam_role {
240241
role_arn = "def"
241242
}
@@ -303,6 +304,7 @@ func TestCreateAccountDacWithAzMI(t *testing.T) {
303304
metastore_id = "abc"
304305
name = "bcd"
305306
is_default = true
307+
api = "account"
306308
azure_managed_identity {
307309
access_connector_id = "def"
308310
}
@@ -371,6 +373,7 @@ func TestCreateAccountDacWithDbGcpSA(t *testing.T) {
371373
metastore_id = "abc"
372374
name = "bcd"
373375
is_default = true
376+
api = "account"
374377
databricks_gcp_service_account {}
375378
`,
376379
}.ApplyAndExpectData(t,

catalog/resource_metastore_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ func TestCreateAccountMetastore(t *testing.T) {
402402
},
403403
Resource: ResourceMetastore(),
404404
AccountID: "100",
405+
Host: "https://accounts.cloud.databricks.com",
405406
Create: true,
406407
HCL: `
407408
name = "a"
@@ -446,6 +447,7 @@ func TestCreateAccountMetastoreWithOwner(t *testing.T) {
446447
},
447448
Resource: ResourceMetastore(),
448449
AccountID: "100",
450+
Host: "https://accounts.cloud.databricks.com",
449451
Create: true,
450452
HCL: `
451453
name = "a"
@@ -497,6 +499,7 @@ func TestCreateAccountMetastore_DeltaSharing(t *testing.T) {
497499
},
498500
Resource: ResourceMetastore(),
499501
AccountID: "100",
502+
Host: "https://accounts.cloud.databricks.com",
500503
Create: true,
501504
HCL: `
502505
name = "a"
@@ -518,6 +521,7 @@ func TestDeleteAccountMetastore(t *testing.T) {
518521
},
519522
Resource: ResourceMetastore(),
520523
AccountID: "100",
524+
Host: "https://accounts.cloud.databricks.com",
521525
Delete: true,
522526
ID: "abc",
523527
HCL: `
@@ -541,6 +545,7 @@ func TestUpdateAccountMetastore_NoChanges(t *testing.T) {
541545
},
542546
Resource: ResourceMetastore(),
543547
AccountID: "100",
548+
Host: "https://accounts.cloud.databricks.com",
544549
ID: "abc",
545550
Update: true,
546551
RequiresNew: true,
@@ -586,6 +591,7 @@ func TestUpdateAccountMetastore_OwnerChanges(t *testing.T) {
586591
},
587592
Resource: ResourceMetastore(),
588593
AccountID: "100",
594+
Host: "https://accounts.cloud.databricks.com",
589595
ID: "abc",
590596
Update: true,
591597
RequiresNew: true,
@@ -643,6 +649,7 @@ func TestUpdateAccountMetastore_Rollback(t *testing.T) {
643649
},
644650
Resource: ResourceMetastore(),
645651
AccountID: "100",
652+
Host: "https://accounts.cloud.databricks.com",
646653
ID: "abc",
647654
Update: true,
648655
RequiresNew: true,
@@ -694,6 +701,7 @@ func TestUpdateAccountMetastore_DeltaSharingScopeOnly(t *testing.T) {
694701
},
695702
Resource: ResourceMetastore(),
696703
AccountID: "100",
704+
Host: "https://accounts.cloud.databricks.com",
697705
ID: "abc",
698706
Update: true,
699707
RequiresNew: true,
@@ -727,6 +735,7 @@ func TestReadAccountMetastore(t *testing.T) {
727735
},
728736
Resource: ResourceMetastore(),
729737
AccountID: "100",
738+
Host: "https://accounts.cloud.databricks.com",
730739
ID: "abc",
731740
Read: true,
732741
New: true,
@@ -748,6 +757,7 @@ func TestReadAccountMetastore_Error(t *testing.T) {
748757
},
749758
Resource: ResourceMetastore(),
750759
AccountID: "100",
760+
Host: "https://accounts.cloud.databricks.com",
751761
ID: "abc",
752762
Read: true,
753763
}.ExpectError(t, "resource is not expected to be removed")

catalog/resource_storage_credential_test.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ func TestCreateAccountStorageCredentialWithOwner(t *testing.T) {
266266
HCL: `
267267
name = "storage_credential_name"
268268
metastore_id = "metastore_id"
269+
api = "account"
269270
aws_iam_role {
270271
role_arn = "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF"
271272
}
@@ -904,25 +905,29 @@ func TestUpdateAzStorageCredentialSpn(t *testing.T) {
904905

905906
func TestStorageCredentialImportAccountLevel(t *testing.T) {
906907
qa.ResourceFixture{
907-
Fixtures: []qa.HTTPFixture{
908-
{
909-
Method: "GET",
910-
Resource: "/api/2.0/accounts/account_id/metastores/metastore_id/storage-credentials/storage_credential_name?",
911-
Response: &catalog.AccountsStorageCredentialInfo{
912-
CredentialInfo: &catalog.StorageCredentialInfo{
913-
Name: "storage_credential_name",
914-
AwsIamRole: &catalog.AwsIamRoleResponse{
915-
RoleArn: "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF",
916-
},
917-
Id: "1234-5678",
918-
MetastoreId: "metastore_id",
908+
MockAccountClientFunc: func(a *mocks.MockAccountClient) {
909+
a.GetMockAccountStorageCredentialsAPI().EXPECT().Get(
910+
mock.Anything,
911+
catalog.GetAccountStorageCredentialRequest{
912+
MetastoreId: "metastore_id",
913+
StorageCredentialName: "storage_credential_name",
914+
},
915+
).Return(&catalog.AccountsStorageCredentialInfo{
916+
CredentialInfo: &catalog.StorageCredentialInfo{
917+
Name: "storage_credential_name",
918+
AwsIamRole: &catalog.AwsIamRoleResponse{
919+
RoleArn: "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF",
919920
},
921+
Id: "1234-5678",
922+
MetastoreId: "metastore_id",
920923
},
921-
},
924+
}, nil)
922925
},
923926
Resource: ResourceStorageCredential(),
924927
AccountID: "account_id",
928+
Host: "https://accounts.cloud.databricks.com",
925929
Read: true,
930+
New: true,
926931
ID: "metastore_id|storage_credential_name",
927932
}.ApplyAndExpectData(t, map[string]any{
928933
"metastore_id": "metastore_id",

0 commit comments

Comments
 (0)