From 900e145acba341ee94f825ee32a94ead82091e4c Mon Sep 17 00:00:00 2001 From: Harsh Shah Date: Wed, 15 May 2024 12:12:59 -0700 Subject: [PATCH] add more tests --- settings/all_settings.go | 2 +- ...ompliance_security_profile_setting_test.go | 173 +++++++++++++++++- 2 files changed, 173 insertions(+), 2 deletions(-) diff --git a/settings/all_settings.go b/settings/all_settings.go index a01698d6e3..b9abe5a641 100644 --- a/settings/all_settings.go +++ b/settings/all_settings.go @@ -17,7 +17,7 @@ func AllSettingsResources() map[string]common.Resource { return map[string]common.Resource{ "default_namespace": makeSettingResource[settings.DefaultNamespaceSetting, *databricks.WorkspaceClient](defaultNamespaceSetting), "restrict_workspace_admins": makeSettingResource[settings.RestrictWorkspaceAdminsSetting, *databricks.WorkspaceClient](restrictWsAdminsSetting), - "compliance_security_profile_workspace": makeSettingResource[settings.ComplianceSecurityProfileSetting, *databricks.WorkspaceClient](complianceSecurityProfileSetting), + "compliance_security_profile_workspace": makeSettingResource[settings.ComplianceSecurityProfileSetting, *databricks.WorkspaceClient](complianceSecurityProfileSetting), "enhanced_security_monitoring_workspace": makeSettingResource[settings.EnhancedSecurityMonitoringSetting, *databricks.WorkspaceClient](enhancedSecurityMonitoringSetting), } } diff --git a/settings/resource_compliance_security_profile_setting_test.go b/settings/resource_compliance_security_profile_setting_test.go index 5e4ee44895..a10a6bae0a 100644 --- a/settings/resource_compliance_security_profile_setting_test.go +++ b/settings/resource_compliance_security_profile_setting_test.go @@ -83,5 +83,176 @@ func TestQueryCreateComplianceSecurityProfileSettingWithNoneStandard(t *testing. assert.Equal(t, defaultSettingId, d.Id()) assert.Equal(t, "etag2", d.Get(etagAttrName).(string)) - assert.Equal(t, true, d.Get("compliance_security_profile_workspace.0.is_enabled")) + res := d.Get("compliance_security_profile_workspace").([]interface{})[0].(map[string]interface{}) + assert.Equal(t, true, res["is_enabled"]) + assert.Equal(t, "NONE", res["compliance_standards"].([]interface{})[0]) + +} + +func TestQueryReadComplianceSecurityProfileSetting(t *testing.T) { + d, err := qa.ResourceFixture{ + MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) { + w.GetMockComplianceSecurityProfileAPI().EXPECT().Get(mock.Anything, settings.GetComplianceSecurityProfileSettingRequest{ + Etag: "etag1", + }).Return(&settings.ComplianceSecurityProfileSetting{ + Etag: "etag2", + ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{ + IsEnabled: true, + ComplianceStandards: []settings.ComplianceStandard{"HIPAA"}, + }, + SettingName: "default", + }, nil) + }, + Resource: testComplianceSecurityProfileSetting, + Read: true, + HCL: ` + compliance_security_profile_workspace { + is_enabled = true + compliance_standards = ["HIPAA"] + } + etag = "etag1" + `, + ID: defaultSettingId, + }.Apply(t) + + assert.NoError(t, err) + + assert.Equal(t, defaultSettingId, d.Id()) + assert.Equal(t, "etag2", d.Get(etagAttrName).(string)) + res := d.Get("compliance_security_profile_workspace").([]interface{})[0].(map[string]interface{}) + assert.Equal(t, true, res["is_enabled"]) + assert.Equal(t, "HIPAA", res["compliance_standards"].([]interface{})[0]) +} + +func TestQueryUpdateComplianceSecurityProfileSetting(t *testing.T) { + d, err := qa.ResourceFixture{ + MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) { + e := w.GetMockComplianceSecurityProfileAPI().EXPECT() + e.Update(mock.Anything, settings.UpdateComplianceSecurityProfileSettingRequest{ + AllowMissing: true, + FieldMask: complianceSecurityProfileFieldMask, + Setting: settings.ComplianceSecurityProfileSetting{ + Etag: "etag1", + ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{ + IsEnabled: true, + ComplianceStandards: []settings.ComplianceStandard{"HIPAA", "PCI_DSS"}, + }, + SettingName: "default", + }, + }).Return(&settings.ComplianceSecurityProfileSetting{ + Etag: "etag2", + ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{ + IsEnabled: true, + ComplianceStandards: []settings.ComplianceStandard{"HIPAA", "PCI_DSS"}, + }, + SettingName: "default", + }, nil) + e.Get(mock.Anything, settings.GetComplianceSecurityProfileSettingRequest{ + Etag: "etag2", + }).Return(&settings.ComplianceSecurityProfileSetting{ + Etag: "etag2", + ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{ + IsEnabled: true, + ComplianceStandards: []settings.ComplianceStandard{"HIPAA", "PCI_DSS"}, + }, + SettingName: "default", + }, nil) + }, + Resource: testComplianceSecurityProfileSetting, + Update: true, + HCL: ` + compliance_security_profile_workspace { + is_enabled = true + compliance_standards = ["HIPAA", "PCI_DSS"] + } + etag = "etag1" + `, + ID: defaultSettingId, + }.Apply(t) + + assert.NoError(t, err) + + assert.Equal(t, defaultSettingId, d.Id()) + assert.Equal(t, "etag2", d.Get(etagAttrName).(string)) + res := d.Get("compliance_security_profile_workspace").([]interface{})[0].(map[string]interface{}) + assert.Equal(t, true, res["is_enabled"]) + assert.Equal(t, "HIPAA", res["compliance_standards"].([]interface{})[0]) + assert.Equal(t, "PCI_DSS", res["compliance_standards"].([]interface{})[1]) +} + +func TestQueryUpdateComplianceSecurityProfileSettingWithConflict(t *testing.T) { + d, err := qa.ResourceFixture{ + MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) { + e := w.GetMockComplianceSecurityProfileAPI().EXPECT() + e.Update(mock.Anything, settings.UpdateComplianceSecurityProfileSettingRequest{ + AllowMissing: true, + FieldMask: complianceSecurityProfileFieldMask, + Setting: settings.ComplianceSecurityProfileSetting{ + Etag: "etag1", + ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{ + IsEnabled: true, + ComplianceStandards: []settings.ComplianceStandard{"HIPAA"}, + }, + SettingName: "default", + }, + }).Return(nil, &apierr.APIError{ + ErrorCode: "RESOURCE_CONFLICT", + StatusCode: 409, + Message: "SomeMessage", + Details: []apierr.ErrorDetail{{ + Type: "type.googleapis.com/google.rpc.ErrorInfo", + Metadata: map[string]string{ + etagAttrName: "etag2", + }, + }}, + }) + e.Update(mock.Anything, settings.UpdateComplianceSecurityProfileSettingRequest{ + AllowMissing: true, + FieldMask: complianceSecurityProfileFieldMask, + Setting: settings.ComplianceSecurityProfileSetting{ + Etag: "etag2", + ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{ + IsEnabled: true, + ComplianceStandards: []settings.ComplianceStandard{"HIPAA"}, + }, + SettingName: "default", + }, + }).Return(&settings.ComplianceSecurityProfileSetting{ + Etag: "etag3", + ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{ + IsEnabled: true, + ComplianceStandards: []settings.ComplianceStandard{"HIPAA"}, + }, + SettingName: "default", + }, nil) + e.Get(mock.Anything, settings.GetComplianceSecurityProfileSettingRequest{ + Etag: "etag3", + }).Return(&settings.ComplianceSecurityProfileSetting{ + Etag: "etag3", + ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{ + IsEnabled: true, + ComplianceStandards: []settings.ComplianceStandard{"HIPAA"}, + }, + SettingName: "default", + }, nil) + }, + Resource: testComplianceSecurityProfileSetting, + Update: true, + HCL: ` + compliance_security_profile_workspace { + is_enabled = true + compliance_standards = ["HIPAA"] + } + etag = "etag1" + `, + ID: defaultSettingId, + }.Apply(t) + + assert.NoError(t, err) + + assert.Equal(t, defaultSettingId, d.Id()) + assert.Equal(t, "etag3", d.Get(etagAttrName).(string)) + res := d.Get("compliance_security_profile_workspace").([]interface{})[0].(map[string]interface{}) + assert.Equal(t, true, res["is_enabled"]) + assert.Equal(t, "HIPAA", res["compliance_standards"].([]interface{})[0]) }