Skip to content

Commit

Permalink
role acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hsafra committed Jan 11, 2024
1 parent 367d512 commit 5c805a9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/provider/resource_aerospike_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (r *AerospikeRole) Create(ctx context.Context, req resource.CreateRequest,

// Write logs using the tflog package
tflog.Trace(ctx, "created role: "+roleName+" with privileges: "+strings.Join(printPrivs, ", ")+" whitelist: "+
strings.Join(whiteList, ", ")+" read quota: "+string(readQuota)+" write quota:"+string(writeQuota))
strings.Join(whiteList, ", ")+" read quota: "+fmt.Sprint(readQuota)+" write quota:"+fmt.Sprint(writeQuota))

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down
53 changes: 53 additions & 0 deletions internal/provider/resource_aerospike_role_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Harel Safra
// SPDX-License-Identifier: MPL-2.0

package provider

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccAerospikeRole(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccAerospikeRoleConfig("testrole1", "[{privilege=\"read\"}]", "[\"1.1.1.1\"]"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("aerospike_role.testrole1", "role_name", "testrole1"),
resource.TestCheckResourceAttr("aerospike_role.testrole1", "white_list.0", "1.1.1.1"),
),
},
// update privs
{
Config: testAccAerospikeRoleConfig("testrole1", "[{privilege=\"write\",namespace=\"aerospike\",set=\"test\"}]", "[\"1.1.1.1\"]"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("aerospike_role.testrole1", "role_name", "testrole1"),
resource.TestCheckResourceAttr("aerospike_role.testrole1", "white_list.0", "1.1.1.1"),
),
},
// update white list
{
Config: testAccAerospikeRoleConfig("testrole1", "[{privilege=\"write\",namespace=\"aerospike\",set=\"test\"}]", "[\"2.2.2.2\"]"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("aerospike_role.testrole1", "role_name", "testrole1"),
resource.TestCheckResourceAttr("aerospike_role.testrole1", "white_list.0", "2.2.2.2"),
),
},
},
})
}

func testAccAerospikeRoleConfig(roleName string, privileges string, white_list string) string {
return fmt.Sprintf(`
resource "aerospike_role" "%[1]s" {
role_name = "%[1]s"
privileges = %[2]s
white_list = %[3]s
}`, roleName, privileges, white_list)
}
20 changes: 6 additions & 14 deletions tests/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ resource "aerospike_role" "role2" {
privileges = [
{
privilege = "read"
namespace="aerospike"
set="set1"
namespace = "aerospike"
set = "set1"
}
]
}
Expand All @@ -43,20 +43,12 @@ resource "aerospike_role" "role3" {
{
privilege = "sys-admin"
},
{
privilege = "read-write"
namespace="aerospike"
set="harel"
}
{ privilege = "read-write", namespace = "aerospike", set = "harel" }
]
}

resource "aerospike_role" "role6" {
role_name = "role6"
privileges = [
{
privilege = "read-write"
}
]
white_list=["1.1.1.5","3.3.3.3"]
role_name = "role6"
privileges = [{ privilege = "read-write" }]
white_list = ["1.1.1.5", "3.3.3.3"]
}

0 comments on commit 5c805a9

Please sign in to comment.