fix: fix lintings
This commit is contained in:
parent
8d5c0560f1
commit
cdbfc56fd0
7 changed files with 52 additions and 130 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -266,13 +267,19 @@ func setupMockServer() *httptest.Server {
|
|||
switch r.Method {
|
||||
case http.MethodPost:
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
err := json.NewEncoder(w).Encode(map[string]string{
|
||||
"id": "mock-id-123",
|
||||
"name": "test-resource",
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
case http.MethodGet:
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode([]map[string]string{})
|
||||
err := json.NewEncoder(w).Encode([]map[string]string{})
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -284,7 +291,10 @@ func TestUnitResourceCreate(t *testing.T) {
|
|||
defer server.Close()
|
||||
|
||||
// Configure provider to use mock server URL
|
||||
os.Setenv("API_ENDPOINT", server.URL)
|
||||
err := os.Setenv("API_ENDPOINT", server.URL)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
// Run unit tests against mock
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
|
|
@ -503,45 +502,6 @@ func (r *userResource) IdentitySchema(
|
|||
}
|
||||
}
|
||||
|
||||
func mapFields(userResp *postgresflex.GetUserResponse, model *resourceModel, region string) error {
|
||||
if userResp == nil {
|
||||
return fmt.Errorf("response is nil")
|
||||
}
|
||||
if model == nil {
|
||||
return fmt.Errorf("model input is nil")
|
||||
}
|
||||
user := userResp
|
||||
|
||||
var userId int64
|
||||
if model.UserId.ValueInt64() != 0 {
|
||||
userId = model.UserId.ValueInt64()
|
||||
} else if user.Id != nil {
|
||||
userId = *user.Id
|
||||
} else {
|
||||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
|
||||
model.UserId = types.Int64Value(userId)
|
||||
model.Name = types.StringPointerValue(user.Name)
|
||||
|
||||
if user.Roles == nil {
|
||||
model.Roles = types.List(types.SetNull(types.StringType))
|
||||
} else {
|
||||
var roles []attr.Value
|
||||
for _, role := range *user.Roles {
|
||||
roles = append(roles, types.StringValue(string(role)))
|
||||
}
|
||||
rolesSet, diags := types.SetValue(types.StringType, roles)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf("failed to map roles: %w", core.DiagsToError(diags))
|
||||
}
|
||||
model.Roles = types.List(rolesSet)
|
||||
}
|
||||
model.Region = types.StringValue(region)
|
||||
model.Status = types.StringPointerValue(user.Status)
|
||||
return nil
|
||||
}
|
||||
|
||||
// getUserResource refreshes the resource state by calling the API and mapping the response to the model.
|
||||
// Returns true if the resource state was successfully refreshed, false if the resource does not exist.
|
||||
func (r *userResource) getUserResource(ctx context.Context, model *resourceModel, arg *clientArg) (bool, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue