Skip to content

Commit

Permalink
adds test for instance_secrets_data_source
Browse files Browse the repository at this point in the history
  • Loading branch information
shahadarsh committed Oct 13, 2023
1 parent 5f60ef7 commit add68e5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions internal/provider/instance_secrets_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (d *temboInstanceSecretsDataSource) Schema(_ context.Context, _ datasource.
Description: "Data Source for Tembo Instance Secrets.",
Attributes: map[string]schema.Attribute{
"org_id": schema.StringAttribute{
MarkdownDescription: "Unique ID for the instance generated by Tembo",
MarkdownDescription: "Id of the organization in which the instance will be created",
Required: true,
},
"instance_id": schema.StringAttribute{
Expand All @@ -59,12 +59,13 @@ func (d *temboInstanceSecretsDataSource) Schema(_ context.Context, _ datasource.
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
MarkdownDescription: "Unique ID for the instance generated by Tembo",
MarkdownDescription: "Name of the secret",
Optional: true,
},
"possible_keys": schema.ListAttribute{
Optional: true,
ElementType: types.StringType,
MarkdownDescription: "Possible Keys for the secret",
Optional: true,
ElementType: types.StringType,
},
},
},
Expand Down
50 changes: 50 additions & 0 deletions internal/provider/instance_secrets_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package provider

import (
"fmt"
"os"
"testing"

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

func TestInstanceSecretsDataSource(t *testing.T) {
instanceName := generateInstanceName()
orgId := os.Getenv("ORG_ID")

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Read testing
{
Config: testProviderConfig() + testInstanceResourceCreateConfig(instanceName, orgId) + testInstanceSecretsCreateConfig(orgId),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.#", "4"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.0.name", "app-role"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.0.possible_keys.#", "2"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.0.possible_keys.0", "username"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.0.possible_keys.1", "password"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.1.name", "readonly-role"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.1.possible_keys.#", "2"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.1.possible_keys.0", "username"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.1.possible_keys.1", "password"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.2.name", "superuser-role"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.2.possible_keys.#", "2"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.2.possible_keys.0", "username"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.2.possible_keys.1", "password"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.3.name", "certificate"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.3.possible_keys.#", "1"),
resource.TestCheckResourceAttr("data.tembo_instance_secrets.test_ds", "available_secrets.3.possible_keys.0", "ca.crt"),
),
},
},
})
}

func testInstanceSecretsCreateConfig(orgId string) string {
return fmt.Sprintf(`
data "tembo_instance_secrets" "test_ds" {
org_id = "%v"
instance_id = tembo_instance.test.instance_id
}`, orgId)
}

0 comments on commit add68e5

Please sign in to comment.