feat(objectstorage): Min/Max acceptance tests (#850)
Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
This commit is contained in:
parent
a2cd8a0200
commit
f572b5c386
18 changed files with 192 additions and 135 deletions
|
|
@ -71,7 +71,7 @@ func (r *credentialDataSource) Configure(ctx context.Context, req datasource.Con
|
|||
func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
descriptions := map[string]string{
|
||||
"main": "ObjectStorage credential data source schema. Must have a `region` specified in the provider configuration.",
|
||||
"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`credentials_group_id`,`credential_id`\".",
|
||||
"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`region`,`credentials_group_id`,`credential_id`\".",
|
||||
"credential_id": "The credential ID.",
|
||||
"credentials_group_id": "The credential group ID.",
|
||||
"project_id": "STACKIT Project ID to which the credential group is associated.",
|
||||
|
|
@ -208,6 +208,7 @@ func mapDataSourceFields(credentialResp *objectstorage.AccessKey, model *DataSou
|
|||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
model.CredentialsGroupId.ValueString(),
|
||||
credentialId,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package objectstorage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -13,6 +14,8 @@ import (
|
|||
func TestMapDatasourceFields(t *testing.T) {
|
||||
now := time.Now()
|
||||
|
||||
const testRegion = "eu01"
|
||||
id := fmt.Sprintf("%s,%s,%s", "pid", testRegion, "cgid,cid")
|
||||
tests := []struct {
|
||||
description string
|
||||
input *objectstorage.AccessKey
|
||||
|
|
@ -23,7 +26,7 @@ func TestMapDatasourceFields(t *testing.T) {
|
|||
"default_values",
|
||||
&objectstorage.AccessKey{},
|
||||
DataSourceModel{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
@ -40,7 +43,7 @@ func TestMapDatasourceFields(t *testing.T) {
|
|||
Expires: utils.Ptr(now.Format(time.RFC3339)),
|
||||
},
|
||||
DataSourceModel{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
@ -56,7 +59,7 @@ func TestMapDatasourceFields(t *testing.T) {
|
|||
DisplayName: utils.Ptr(""),
|
||||
},
|
||||
DataSourceModel{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
@ -72,7 +75,7 @@ func TestMapDatasourceFields(t *testing.T) {
|
|||
Expires: utils.Ptr(now.Format(time.RFC3339Nano)),
|
||||
},
|
||||
DataSourceModel{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ func (r *credentialResource) Configure(ctx context.Context, req resource.Configu
|
|||
func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
descriptions := map[string]string{
|
||||
"main": "ObjectStorage credential resource schema. Must have a `region` specified in the provider configuration.",
|
||||
"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`credentials_group_id`,`credential_id`\".",
|
||||
"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`region`,`credentials_group_id`,`credential_id`\".",
|
||||
"credential_id": "The credential ID.",
|
||||
"credentials_group_id": "The credential group ID.",
|
||||
"project_id": "STACKIT Project ID to which the credential group is associated.",
|
||||
|
|
@ -424,17 +424,18 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
|
|||
// The expected format of the resource import identifier is: project_id,credentials_group_id,credential_id
|
||||
func (r *credentialResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
idParts := strings.Split(req.ID, core.Separator)
|
||||
if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" {
|
||||
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics,
|
||||
"Error importing credential",
|
||||
fmt.Sprintf("Expected import identifier with format [project_id],[credentials_group_id],[credential_id], got %q", req.ID),
|
||||
fmt.Sprintf("Expected import identifier with format [project_id],[region],[credentials_group_id],[credential_id], got %q", req.ID),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_group_id"), idParts[1])...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credential_id"), idParts[2])...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("region"), idParts[1])...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_group_id"), idParts[2])...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credential_id"), idParts[3])...)
|
||||
tflog.Info(ctx, "ObjectStorage credential state imported")
|
||||
}
|
||||
|
||||
|
|
@ -507,6 +508,7 @@ func mapFields(credentialResp *objectstorage.CreateAccessKeyResponse, model *Mod
|
|||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
model.CredentialsGroupId.ValueString(),
|
||||
credentialId,
|
||||
}
|
||||
|
|
@ -551,6 +553,7 @@ func readCredentials(ctx context.Context, model *Model, region string, client *o
|
|||
|
||||
idParts := []string{
|
||||
projectId,
|
||||
region,
|
||||
credentialsGroupId,
|
||||
credentialId,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ func (c *objectStorageClientMocked) EnableServiceExecute(_ context.Context, proj
|
|||
|
||||
func TestMapFields(t *testing.T) {
|
||||
now := time.Now()
|
||||
|
||||
const testRegion = "eu01"
|
||||
id := fmt.Sprintf("%s,%s,%s", "pid", testRegion, "cgid,cid")
|
||||
tests := []struct {
|
||||
description string
|
||||
input *objectstorage.CreateAccessKeyResponse
|
||||
|
|
@ -43,7 +44,7 @@ func TestMapFields(t *testing.T) {
|
|||
"default_values",
|
||||
&objectstorage.CreateAccessKeyResponse{},
|
||||
Model{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
@ -64,7 +65,7 @@ func TestMapFields(t *testing.T) {
|
|||
SecretAccessKey: utils.Ptr("secret-key"),
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
@ -84,7 +85,7 @@ func TestMapFields(t *testing.T) {
|
|||
SecretAccessKey: utils.Ptr(""),
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
@ -102,7 +103,7 @@ func TestMapFields(t *testing.T) {
|
|||
Expires: utils.Ptr(now.Format(time.RFC3339Nano)),
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
@ -153,6 +154,8 @@ func TestMapFields(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestEnableProject(t *testing.T) {
|
||||
const testRegion = "eu01"
|
||||
id := fmt.Sprintf("%s,%s,%s", "pid", testRegion, "cgid,cid")
|
||||
tests := []struct {
|
||||
description string
|
||||
expected Model
|
||||
|
|
@ -162,7 +165,7 @@ func TestEnableProject(t *testing.T) {
|
|||
{
|
||||
"default_values",
|
||||
Model{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
@ -177,7 +180,7 @@ func TestEnableProject(t *testing.T) {
|
|||
{
|
||||
"error_response",
|
||||
Model{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
@ -213,7 +216,8 @@ func TestEnableProject(t *testing.T) {
|
|||
|
||||
func TestReadCredentials(t *testing.T) {
|
||||
now := time.Now()
|
||||
|
||||
const testRegion = "eu01"
|
||||
id := fmt.Sprintf("%s,%s,%s", "pid", testRegion, "cgid,cid")
|
||||
tests := []struct {
|
||||
description string
|
||||
mockedResp *objectstorage.ListAccessKeysResponse
|
||||
|
|
@ -238,7 +242,7 @@ func TestReadCredentials(t *testing.T) {
|
|||
},
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
@ -274,7 +278,7 @@ func TestReadCredentials(t *testing.T) {
|
|||
},
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
@ -310,7 +314,7 @@ func TestReadCredentials(t *testing.T) {
|
|||
},
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
Id: types.StringValue(id),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue