Skip to content

Commit

Permalink
format and linting errors resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
stikkireddy committed Jun 15, 2020
1 parent 67edef8 commit 83f6e80
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 97 deletions.
24 changes: 12 additions & 12 deletions databricks/mounts_test.go
Expand Up @@ -8,16 +8,16 @@ import (

func TestValidateMountDirectory(t *testing.T) {
testCases := []struct {
directory string
errorCount int
}{
{"", 0},
{"/directory", 0},
{"directory", 1},
}
for _, tc := range testCases {
_, errs := ValidateMountDirectory(tc.directory, "key")
assert.Lenf(t, errs, tc.errorCount, "directory '%s' does not generate the expected error count", tc.directory)
}
directory string
errorCount int
}{
{"", 0},
{"/directory", 0},
{"directory", 1},
}
for _, tc := range testCases {
_, errs := ValidateMountDirectory(tc.directory, "key")

assert.Lenf(t, errs, tc.errorCount, "directory '%s' does not generate the expected error count", tc.directory)
}
}
16 changes: 8 additions & 8 deletions databricks/provider.go
Expand Up @@ -26,15 +26,15 @@ func Provider(version string) terraform.ResourceProvider {
"databricks_zones": dataSourceClusterZones(),
},
ResourcesMap: map[string]*schema.Resource{
"databricks_token": resourceToken(),
"databricks_secret_scope": resourceSecretScope(),
"databricks_secret": resourceSecret(),
"databricks_secret_acl": resourceSecretACL(),
"databricks_instance_pool": resourceInstancePool(),
"databricks_scim_user": resourceScimUser(),
"databricks_scim_group": resourceScimGroup(),
"databricks_token": resourceToken(),
"databricks_secret_scope": resourceSecretScope(),
"databricks_secret": resourceSecret(),
"databricks_secret_acl": resourceSecretACL(),
"databricks_instance_pool": resourceInstancePool(),
"databricks_scim_user": resourceScimUser(),
"databricks_scim_group": resourceScimGroup(),
// Scim Group is split into multiple components for flexibility to pick and choose
"databricks_group": resourceGroup(),
"databricks_group": resourceGroup(),
"databricks_group_role": resourceGroupRole(),
"databricks_group_member": resourceGroupMember(),
"databricks_notebook": resourceNotebook(),
Expand Down
2 changes: 1 addition & 1 deletion databricks/resource_databricks_azure_adls_gen1_mount.go
Expand Up @@ -39,7 +39,7 @@ func resourceAzureAdlsGen1Mount() *schema.Resource {
Optional: true,
Computed: true,
//Default: "/",
ForceNew: true,
ForceNew: true,
ValidateFunc: ValidateMountDirectory,
},
"mount_name": {
Expand Down
8 changes: 4 additions & 4 deletions databricks/resource_databricks_azure_adls_gen2_mount.go
Expand Up @@ -32,10 +32,10 @@ func resourceAzureAdlsGen2Mount() *schema.Resource {
ForceNew: true,
},
"directory": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: ValidateMountDirectory,
},
"mount_name": {
Expand Down
2 changes: 1 addition & 1 deletion databricks/resource_databricks_azure_blob_mount.go
Expand Up @@ -37,7 +37,7 @@ func resourceAzureBlobMount() *schema.Resource {
Optional: true,
Computed: true,
//Default: "/",
ForceNew: true,
ForceNew: true,
ValidateFunc: ValidateMountDirectory,
},
"mount_name": {
Expand Down
17 changes: 8 additions & 9 deletions databricks/resource_databricks_group.go
Expand Up @@ -22,13 +22,13 @@ func resourceGroup() *schema.Resource {
},
"allow_cluster_create": {
Deprecated: "Will be deprecated in a future release for general permissions api",
Type: schema.TypeBool,
Optional: true,
Type: schema.TypeBool,
Optional: true,
},
"allow_instance_pool_create": {
Deprecated: "Will be deprecated in a future release for general permissions api",
Type: schema.TypeBool,
Optional: true,
Type: schema.TypeBool,
Optional: true,
},
},
Importer: &schema.ResourceImporter{
Expand All @@ -37,7 +37,6 @@ func resourceGroup() *schema.Resource {
}
}


func resourceGroupCreate(d *schema.ResourceData, m interface{}) error {
client := m.(*service.DBApiClient)
groupName := d.Get("display_name").(string)
Expand Down Expand Up @@ -79,7 +78,7 @@ func resourceGroupRead(d *schema.ResourceData, m interface{}) error {
return err
}

err = d.Set("allow_cluster_create",isGroupClusterCreateEntitled(&group))
err = d.Set("allow_cluster_create", isGroupClusterCreateEntitled(&group))
if err != nil {
return err
}
Expand Down Expand Up @@ -134,7 +133,7 @@ func resourceGroupDelete(d *schema.ResourceData, m interface{}) error {
}

func isGroupClusterCreateEntitled(group *model.Group) bool {
for _, entitlement := range(group.Entitlements) {
for _, entitlement := range group.Entitlements {
if entitlement.Value == model.AllowClusterCreateEntitlement {
return true
}
Expand All @@ -143,10 +142,10 @@ func isGroupClusterCreateEntitled(group *model.Group) bool {
}

func isGroupInstancePoolCreateEntitled(group *model.Group) bool {
for _, entitlement := range(group.Entitlements) {
for _, entitlement := range group.Entitlements {
if entitlement.Value == model.AllowClusterCreateEntitlement {
return true
}
}
return false
}
}
14 changes: 7 additions & 7 deletions databricks/resource_databricks_group_aws_test.go
Expand Up @@ -22,7 +22,7 @@ func TestAccAWSGroupResource(t *testing.T) {
randomStr := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
displayName := fmt.Sprintf("tf group test %s", randomStr)
newDisplayName := fmt.Sprintf("new tf group test %s", randomStr)
resource.Test(t, resource.TestCase{
resource.Test(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: testAWSGroupResourceDestroy,
Steps: []resource.TestStep{
Expand All @@ -34,7 +34,7 @@ func TestAccAWSGroupResource(t *testing.T) {
// query the API to retrieve the tokenInfo object
testAWSGroupResourceExists("databricks_group.my_group", &Group, t),
// verify remote values
testAWSGroupValues(t, &Group, displayName,),
testAWSGroupValues(t, &Group, displayName),
// verify local values
resource.TestCheckResourceAttr("databricks_group.my_group", "display_name", displayName),
),
Expand All @@ -44,9 +44,9 @@ func TestAccAWSGroupResource(t *testing.T) {
// use a dynamic configuration with the random name from above
Config: testAWSDatabricksGroup(newDisplayName),
// test to see if new resource is attempted to be planned
PlanOnly: true,
PlanOnly: true,
ExpectNonEmptyPlan: true,
Destroy: false,
Destroy: false,
},
{
ResourceName: "databricks_group.my_group",
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestAccAWSGroupResource_verify_entitlements(t *testing.T) {
// query the API to retrieve the tokenInfo object
testAWSGroupResourceExists("databricks_group.my_group", &Group, t),
// verify remote values
testAWSGroupValues(t, &Group, displayName,),
testAWSGroupValues(t, &Group, displayName),
// verify local values
resource.TestCheckResourceAttr("databricks_group.my_group", "allow_cluster_create", "true"),
resource.TestCheckResourceAttr("databricks_group.my_group", "allow_instance_pool_create", "true"),
Expand All @@ -91,9 +91,9 @@ func TestAccAWSGroupResource_verify_entitlements(t *testing.T) {
// use a dynamic configuration with the random name from above
Config: testAWSDatabricksGroup(newDisplayName),
// test to see if new resource is attempted to be planned
PlanOnly: true,
PlanOnly: true,
ExpectNonEmptyPlan: true,
Destroy: false,
Destroy: false,
},
},
})
Expand Down
12 changes: 6 additions & 6 deletions databricks/resource_databricks_group_azure_test.go
Expand Up @@ -34,7 +34,7 @@ func TestAccAzureGroupResource(t *testing.T) {
// query the API to retrieve the tokenInfo object
testAzureGroupResourceExists("databricks_group.my_group", &Group, t),
// verify remote values
testAzureGroupValues(t, &Group, displayName,),
testAzureGroupValues(t, &Group, displayName),
// verify local values
resource.TestCheckResourceAttr("databricks_group.my_group", "display_name", displayName),
),
Expand All @@ -44,9 +44,9 @@ func TestAccAzureGroupResource(t *testing.T) {
// use a dynamic configuration with the random name from above
Config: testAzureDatabricksGroup(newDisplayName),
// test to see if new resource is attempted to be planned
PlanOnly: true,
PlanOnly: true,
ExpectNonEmptyPlan: true,
Destroy: false,
Destroy: false,
},
},
})
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestAccAzureGroupResource_verify_entitlements(t *testing.T) {
// query the API to retrieve the tokenInfo object
testAzureGroupResourceExists("databricks_group.my_group", &Group, t),
// verify remote values
testAzureGroupValues(t, &Group, displayName,),
testAzureGroupValues(t, &Group, displayName),
// verify local values
resource.TestCheckResourceAttr("databricks_group.my_group", "allow_cluster_create", "true"),
resource.TestCheckResourceAttr("databricks_group.my_group", "allow_instance_pool_create", "true"),
Expand All @@ -87,9 +87,9 @@ func TestAccAzureGroupResource_verify_entitlements(t *testing.T) {
// use a dynamic configuration with the random name from above
Config: testAzureDatabricksGroup(newDisplayName),
// test to see if new resource is attempted to be planned
PlanOnly: true,
PlanOnly: true,
ExpectNonEmptyPlan: true,
Destroy: false,
Destroy: false,
},
},
})
Expand Down
17 changes: 6 additions & 11 deletions databricks/resource_databricks_group_member.go
Expand Up @@ -31,15 +31,13 @@ func resourceGroupMember() *schema.Resource {
}
}



func resourceGroupMemberCreate(d *schema.ResourceData, m interface{}) error {
client := m.(*service.DBApiClient)
groupID := d.Get("group_id").(string)
memberID := d.Get("member_id").(string)

groupMemberID := &GroupMemberID{
GroupID: groupID,
GroupID: groupID,
MemberID: memberID,
}

Expand Down Expand Up @@ -85,8 +83,6 @@ func resourceGroupMemberRead(d *schema.ResourceData, m interface{}) error {
return err
}



func resourceGroupMemberDelete(d *schema.ResourceData, m interface{}) error {
id := d.Id()
client := m.(*service.DBApiClient)
Expand All @@ -98,9 +94,8 @@ func resourceGroupMemberDelete(d *schema.ResourceData, m interface{}) error {
return err
}


type GroupMemberID struct {
GroupID string
GroupID string
MemberID string
}

Expand All @@ -111,16 +106,16 @@ func (g GroupMemberID) String() string {
func parseGroupMemberID(id string) *GroupMemberID {
parts := strings.Split(id, "|")
return &GroupMemberID{
GroupID:parts[0],
MemberID:parts[1],
GroupID: parts[0],
MemberID: parts[1],
}
}

func iMemberInGroup(member string, group *model.Group) bool {
for _, groupMember := range(group.Members) {
for _, groupMember := range group.Members {
if groupMember.Value == member {
return true
}
}
return false
}
}
22 changes: 13 additions & 9 deletions databricks/resource_databricks_group_member_aws_test.go
Expand Up @@ -23,7 +23,8 @@ func TestAccAWSGroupMemberResource(t *testing.T) {
defer func() {
client := testAccProvider.Meta().(*service.DBApiClient)
if client != nil && manuallyCreatedGroup != nil {
client.Groups().Delete(manuallyCreatedGroup.ID)
err := client.Groups().Delete(manuallyCreatedGroup.ID)
assert.NoError(t, err, err)
}
}()

Expand All @@ -49,12 +50,13 @@ func TestAccAWSGroupMemberResource(t *testing.T) {
},
{
PreConfig: func() {
// manually create subgroup c
// manually create subgroup c
client := testAccProvider.Meta().(*service.DBApiClient)
subGroupC, _ := client.Groups().Create("manually-created-group", nil, nil, nil)
manuallyCreatedGroup = &subGroupC
// Add new subgroup to current group
client.Groups().Patch(group.ID, []string{manuallyCreatedGroup.ID}, nil, model.GroupMembersPath)
// Add new subgroup to current group
err := client.Groups().Patch(group.ID, []string{manuallyCreatedGroup.ID}, nil, model.GroupMembersPath)
assert.NoError(t, err, err)
},
Config: testAWSGroupMemberResource(groupName),
// compose a basic test, checking both remote and local values
Expand Down Expand Up @@ -89,11 +91,12 @@ func TestAccAWSGroupMemberResource(t *testing.T) {
// Test behavior to expect to attempt to create new role mapping because role is gone
PreConfig: func() {
client := testAccProvider.Meta().(*service.DBApiClient)
client.Groups().Delete(group.ID)
err := client.Groups().Delete(group.ID)
assert.NoError(t, err, err)
},
PlanOnly: true,
PlanOnly: true,
ExpectNonEmptyPlan: true,
Destroy: false,
Destroy: false,
},
{
// use a dynamic configuration with the random name from above
Expand All @@ -102,7 +105,8 @@ func TestAccAWSGroupMemberResource(t *testing.T) {
// Lets delete the manually created group
PreConfig: func() {
client := testAccProvider.Meta().(*service.DBApiClient)
client.Groups().Delete(manuallyCreatedGroup.ID)
err := client.Groups().Delete(manuallyCreatedGroup.ID)
assert.NoError(t, err, err)
manuallyCreatedGroup = nil
},
// compose a basic test, checking both remote and local values
Expand Down Expand Up @@ -138,7 +142,7 @@ func testAWSGroupMemberResourceDestroy(s *terraform.State) error {
func testAWSGroupMemberValues(t *testing.T, group *model.Group, displayName string, memberCount int) resource.TestCheckFunc {
return func(s *terraform.State) error {
assert.True(t, group.DisplayName == displayName)
assert.Equal(t, memberCount,len(group.Members), "member count is not matching")
assert.Equal(t, memberCount, len(group.Members), "member count is not matching")
return nil
}
}
Expand Down

0 comments on commit 83f6e80

Please sign in to comment.