Skip to content

Commit

Permalink
fix test again
Browse files Browse the repository at this point in the history
  • Loading branch information
nkvuong committed Nov 15, 2024
1 parent ab0ea7f commit c21c310
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 9 additions & 2 deletions catalog/resource_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ var credentialSchema = common.StructToSchema(catalog.CredentialInfo{},
common.CustomizeSchemaPath(m, cred).SetAtLeastOneOf(alofServiceCreds)
}

common.MustSchemaPath(m, "name").Required = true
common.MustSchemaPath(m, "purpose").Required = true
for _, required := range []string{"name", "purpose"} {
common.MustSchemaPath(m, required).Required = true
common.MustSchemaPath(m, required).Optional = false
}

common.MustSchemaPath(m, "id").Computed = true
common.MustSchemaPath(m, "aws_iam_role", "external_id").Computed = true
Expand All @@ -38,6 +40,10 @@ var credentialSchema = common.StructToSchema(catalog.CredentialInfo{},
return old == "false" && new == "true"
},
}
m["credential_id"] = &schema.Schema{
Type: schema.TypeString,
Computed: true,
}
m["name"].DiffSuppressFunc = common.EqualFoldDiffSuppress
return m
})
Expand Down Expand Up @@ -83,6 +89,7 @@ func ResourceCredential() common.Resource {
if err != nil {
return err
}
d.Set("credential_id", cred.Id)
return common.StructToData(cred, credentialSchema, d)
},
Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
Expand Down
10 changes: 10 additions & 0 deletions catalog/resource_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ func TestCreateCredential(t *testing.T) {
RoleArn: "def",
},
Comment: "c",
Purpose: "SERVICE",
}).Return(&catalog.CredentialInfo{
Name: "a",
AwsIamRole: &catalog.AwsIamRole{
RoleArn: "def",
},
Purpose: "SERVICE",
Comment: "c",
}, nil)
e.GetCredentialByNameArg(mock.Anything, "a").Return(&catalog.CredentialInfo{
Expand All @@ -36,6 +38,7 @@ func TestCreateCredential(t *testing.T) {
RoleArn: "def",
ExternalId: "123",
},
Purpose: "SERVICE",
MetastoreId: "d",
Id: "1234-5678",
Owner: "f",
Expand All @@ -49,12 +52,14 @@ func TestCreateCredential(t *testing.T) {
aws_iam_role {
role_arn = "def"
}
purpose = "SERVICE"
comment = "c"
`,
}.ApplyAndExpectData(t, map[string]any{
"aws_iam_role.0.external_id": "123",
"aws_iam_role.0.role_arn": "def",
"name": "a",
"purpose": "SERVICE",
})
}

Expand All @@ -68,12 +73,14 @@ func TestCreateIsolatedCredential(t *testing.T) {
RoleArn: "def",
},
Comment: "c",
Purpose: "SERVICE",
}).Return(&catalog.CredentialInfo{
Name: "a",
AwsIamRole: &catalog.AwsIamRole{
RoleArn: "def",
ExternalId: "123",
},
Purpose: "SERVICE",
MetastoreId: "d",
Id: "1234-5678",
Owner: "f",
Expand All @@ -91,6 +98,7 @@ func TestCreateIsolatedCredential(t *testing.T) {
RoleArn: "def",
ExternalId: "123",
},
Purpose: "SERVICE",
MetastoreId: "d",
Id: "1234-5678",
Owner: "f",
Expand Down Expand Up @@ -123,6 +131,7 @@ func TestCreateIsolatedCredential(t *testing.T) {
RoleArn: "def",
ExternalId: "123",
},
Purpose: "SERVICE",
MetastoreId: "d",
Id: "1234-5678",
Owner: "f",
Expand All @@ -137,6 +146,7 @@ func TestCreateIsolatedCredential(t *testing.T) {
role_arn = "def"
}
comment = "c"
purpose = "SERVICE"
isolation_mode = "ISOLATION_MODE_ISOLATED"
`,
}.ApplyAndExpectData(t, map[string]any{
Expand Down

0 comments on commit c21c310

Please sign in to comment.