Fix/fix tests (#18)
* fix: fix and adjust tests to new api * fix: add missing testdata file * fix: add missing docs * fix: ignore docs flow for now * fix: fix linting
This commit is contained in:
parent
25fb4453f0
commit
5b6576da1c
34 changed files with 513 additions and 340 deletions
|
|
@ -127,6 +127,7 @@ func (r *databaseDataSource) Schema(_ context.Context, _ datasource.SchemaReques
|
|||
// Read refreshes the Terraform state with the latest data.
|
||||
func (r *databaseDataSource) Read(
|
||||
ctx context.Context,
|
||||
// TODO - make it pointer
|
||||
req datasource.ReadRequest,
|
||||
resp *datasource.ReadResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ type databaseResource struct {
|
|||
// Use the modifier to set the effective region in the current plan.
|
||||
func (r *databaseResource) ModifyPlan(
|
||||
ctx context.Context,
|
||||
// TODO - make it pointer
|
||||
req resource.ModifyPlanRequest,
|
||||
resp *resource.ModifyPlanResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
|
|
@ -200,6 +201,7 @@ func (r *databaseResource) Schema(_ context.Context, _ resource.SchemaRequest, r
|
|||
// Create creates the resource and sets the initial Terraform state.
|
||||
func (r *databaseResource) Create(
|
||||
ctx context.Context,
|
||||
// TODO - make it pointer
|
||||
req resource.CreateRequest,
|
||||
resp *resource.CreateResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
|
|
@ -290,6 +292,7 @@ func (r *databaseResource) Create(
|
|||
// Read refreshes the Terraform state with the latest data.
|
||||
func (r *databaseResource) Read(
|
||||
ctx context.Context,
|
||||
// TODO - make it pointer
|
||||
req resource.ReadRequest,
|
||||
resp *resource.ReadResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
|
|
@ -314,7 +317,7 @@ func (r *databaseResource) Read(
|
|||
databaseResp, err := getDatabase(ctx, r.client, projectId, region, instanceId, databaseId)
|
||||
if err != nil {
|
||||
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
|
||||
if (ok && oapiErr.StatusCode == http.StatusNotFound) || errors.Is(err, databaseNotFoundErr) {
|
||||
if (ok && oapiErr.StatusCode == http.StatusNotFound) || errors.Is(err, errDatabaseNotFound) {
|
||||
resp.State.RemoveResource(ctx)
|
||||
return
|
||||
}
|
||||
|
|
@ -452,7 +455,7 @@ func mapFields(databaseResp *postgresflexalpha.ListDatabase, model *Model, regio
|
|||
|
||||
ownerStr, err := mapOwner(databaseResp)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error mapping owner: %v", err)
|
||||
return fmt.Errorf("error mapping owner: %w", err)
|
||||
}
|
||||
|
||||
model.Owner = types.StringPointerValue(ownerStr)
|
||||
|
|
@ -487,7 +490,7 @@ func toCreatePayload(model *Model) (*postgresflexalpha.CreateDatabaseRequestPayl
|
|||
}, nil
|
||||
}
|
||||
|
||||
var databaseNotFoundErr = errors.New("database not found")
|
||||
var errDatabaseNotFound = errors.New("database not found")
|
||||
|
||||
// The API does not have a GetDatabase endpoint, only ListDatabases
|
||||
func getDatabase(
|
||||
|
|
@ -508,5 +511,5 @@ func getDatabase(
|
|||
return &database, nil
|
||||
}
|
||||
}
|
||||
return nil, databaseNotFoundErr
|
||||
return nil, errDatabaseNotFound
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,23 +5,22 @@ import (
|
|||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
|
||||
postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
|
||||
)
|
||||
|
||||
func TestMapFields(t *testing.T) {
|
||||
const testRegion = "region"
|
||||
tests := []struct {
|
||||
description string
|
||||
input *postgresflexalpha.ListDatabase
|
||||
input *postgresflex.ListDatabase
|
||||
region string
|
||||
expected Model
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
&postgresflexalpha.ListDatabase{
|
||||
&postgresflex.ListDatabase{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
},
|
||||
testRegion,
|
||||
|
|
@ -38,7 +37,7 @@ func TestMapFields(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"simple_values",
|
||||
&postgresflexalpha.ListDatabase{
|
||||
&postgresflex.ListDatabase{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Name: utils.Ptr("dbname"),
|
||||
Owner: utils.Ptr("username"),
|
||||
|
|
@ -57,7 +56,7 @@ func TestMapFields(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"null_fields_and_int_conversions",
|
||||
&postgresflexalpha.ListDatabase{
|
||||
&postgresflex.ListDatabase{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Name: utils.Ptr(""),
|
||||
Owner: utils.Ptr(""),
|
||||
|
|
@ -83,14 +82,14 @@ func TestMapFields(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"empty_response",
|
||||
&postgresflexalpha.ListDatabase{},
|
||||
&postgresflex.ListDatabase{},
|
||||
testRegion,
|
||||
Model{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_resource_id",
|
||||
&postgresflexalpha.ListDatabase{
|
||||
&postgresflex.ListDatabase{
|
||||
Id: utils.Ptr(int64(0)),
|
||||
Name: utils.Ptr("dbname"),
|
||||
Owner: utils.Ptr("username"),
|
||||
|
|
@ -129,7 +128,7 @@ func TestToCreatePayload(t *testing.T) {
|
|||
tests := []struct {
|
||||
description string
|
||||
input *Model
|
||||
expected *postgresflex.CreateDatabasePayload
|
||||
expected *postgresflex.CreateDatabaseRequestPayload
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
|
|
@ -138,11 +137,9 @@ func TestToCreatePayload(t *testing.T) {
|
|||
Name: types.StringValue("dbname"),
|
||||
Owner: types.StringValue("username"),
|
||||
},
|
||||
&postgresflex.CreateDatabasePayload{
|
||||
Name: utils.Ptr("dbname"),
|
||||
Options: &map[string]string{
|
||||
"owner": "username",
|
||||
},
|
||||
&postgresflex.CreateDatabaseRequestPayload{
|
||||
Name: utils.Ptr("dbname"),
|
||||
Owner: utils.Ptr("username"),
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
@ -152,11 +149,9 @@ func TestToCreatePayload(t *testing.T) {
|
|||
Name: types.StringNull(),
|
||||
Owner: types.StringNull(),
|
||||
},
|
||||
&postgresflex.CreateDatabasePayload{
|
||||
Name: nil,
|
||||
Options: &map[string]string{
|
||||
"owner": "",
|
||||
},
|
||||
&postgresflex.CreateDatabaseRequestPayload{
|
||||
Name: nil,
|
||||
Owner: nil,
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue