Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
harshshah-db committed May 15, 2024
1 parent dab645c commit 900e145
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 2 deletions.
2 changes: 1 addition & 1 deletion settings/all_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
173 changes: 172 additions & 1 deletion settings/resource_compliance_security_profile_setting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}

0 comments on commit 900e145

Please sign in to comment.