feat: more_tests (#85)
Some checks failed
Publish / Check GoReleaser config (push) Successful in 7s
Publish / Publish provider (push) Successful in 7m41s
CI Workflow / Check GoReleaser config (pull_request) Successful in 6s
CI Workflow / Prepare GO cache (pull_request) Successful in 10m18s
CI Workflow / Test readiness for publishing provider (pull_request) Has been cancelled
CI Workflow / Code coverage report (pull_request) Has been cancelled
CI Workflow / CI run build and linting (pull_request) Has been cancelled
CI Workflow / CI run tests (pull_request) Has been cancelled
TF Acceptance Tests Workflow / Acceptance Tests (pull_request) Failing after 26m13s
Some checks failed
Publish / Check GoReleaser config (push) Successful in 7s
Publish / Publish provider (push) Successful in 7m41s
CI Workflow / Check GoReleaser config (pull_request) Successful in 6s
CI Workflow / Prepare GO cache (pull_request) Successful in 10m18s
CI Workflow / Test readiness for publishing provider (pull_request) Has been cancelled
CI Workflow / Code coverage report (pull_request) Has been cancelled
CI Workflow / CI run build and linting (pull_request) Has been cancelled
CI Workflow / CI run tests (pull_request) Has been cancelled
TF Acceptance Tests Workflow / Acceptance Tests (pull_request) Failing after 26m13s
## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Reviewed-on: #85
This commit is contained in:
parent
3790894563
commit
dd77da71dd
37 changed files with 2473 additions and 1742 deletions
|
|
@ -30,35 +30,35 @@ const (
|
|||
type APIClientInterface interface {
|
||||
GetInstanceRequest(
|
||||
ctx context.Context,
|
||||
projectId, region, instanceId string,
|
||||
projectID, region, instanceID string,
|
||||
) sqlserverflex.ApiGetInstanceRequestRequest
|
||||
GetDatabaseRequest(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
projectID string,
|
||||
region string,
|
||||
instanceId string,
|
||||
instanceID string,
|
||||
databaseName string,
|
||||
) sqlserverflex.ApiGetDatabaseRequestRequest
|
||||
GetUserRequest(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
projectID string,
|
||||
region string,
|
||||
instanceId string,
|
||||
userId int64,
|
||||
instanceID string,
|
||||
userID int64,
|
||||
) sqlserverflex.ApiGetUserRequestRequest
|
||||
|
||||
ListRolesRequest(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
projectID string,
|
||||
region string,
|
||||
instanceId string,
|
||||
instanceID string,
|
||||
) sqlserverflex.ApiListRolesRequestRequest
|
||||
|
||||
ListUsersRequest(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
projectID string,
|
||||
region string,
|
||||
instanceId string,
|
||||
instanceID string,
|
||||
) sqlserverflex.ApiListUsersRequestRequest
|
||||
}
|
||||
|
||||
|
|
@ -66,10 +66,10 @@ type APIClientInterface interface {
|
|||
type APIClientUserInterface interface {
|
||||
DeleteUserRequestExecute(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
projectID string,
|
||||
region string,
|
||||
instanceId string,
|
||||
userId int64,
|
||||
instanceID string,
|
||||
userID int64,
|
||||
) error
|
||||
}
|
||||
|
||||
|
|
@ -77,11 +77,11 @@ type APIClientUserInterface interface {
|
|||
func CreateInstanceWaitHandler(
|
||||
ctx context.Context,
|
||||
a APIClientInterface,
|
||||
projectId, instanceId, region string,
|
||||
projectID, instanceID, region string,
|
||||
) *wait.AsyncActionHandler[sqlserverflex.GetInstanceResponse] {
|
||||
handler := wait.New(
|
||||
func() (waitFinished bool, response *sqlserverflex.GetInstanceResponse, err error) {
|
||||
s, err := a.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
|
||||
s, err := a.GetInstanceRequest(ctx, projectID, region, instanceID).Execute()
|
||||
if err != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(err, &oapiErr)
|
||||
|
|
@ -95,7 +95,7 @@ func CreateInstanceWaitHandler(
|
|||
return false, nil, fmt.Errorf("api error: %w", err)
|
||||
}
|
||||
}
|
||||
if s == nil || s.Id != instanceId {
|
||||
if s == nil || s.Id != instanceID {
|
||||
return false, nil, nil
|
||||
}
|
||||
switch strings.ToLower(string(s.Status)) {
|
||||
|
|
@ -113,7 +113,7 @@ func CreateInstanceWaitHandler(
|
|||
|
||||
tflog.Info(ctx, "trying to get roles")
|
||||
time.Sleep(10 * time.Second)
|
||||
_, rolesErr := a.ListRolesRequest(ctx, projectId, region, instanceId).Execute()
|
||||
_, rolesErr := a.ListRolesRequest(ctx, projectID, region, instanceID).Execute()
|
||||
if rolesErr != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(rolesErr, &oapiErr)
|
||||
|
|
@ -137,7 +137,7 @@ func CreateInstanceWaitHandler(
|
|||
|
||||
tflog.Info(ctx, "trying to get users")
|
||||
time.Sleep(10 * time.Second)
|
||||
_, usersErr := a.ListUsersRequest(ctx, projectId, region, instanceId).Execute()
|
||||
_, usersErr := a.ListUsersRequest(ctx, projectID, region, instanceID).Execute()
|
||||
if usersErr != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(usersErr, &oapiErr)
|
||||
|
|
@ -162,13 +162,13 @@ func CreateInstanceWaitHandler(
|
|||
case strings.ToLower(InstanceStateUnknown):
|
||||
return true, nil, fmt.Errorf(
|
||||
"create failed for instance %s with status %s",
|
||||
instanceId,
|
||||
instanceID,
|
||||
InstanceStateUnknown,
|
||||
)
|
||||
case strings.ToLower(InstanceStateFailed):
|
||||
return true, nil, fmt.Errorf(
|
||||
"create failed for instance %s with status %s",
|
||||
instanceId,
|
||||
instanceID,
|
||||
InstanceStateFailed,
|
||||
)
|
||||
case strings.ToLower(InstanceStatePending), strings.ToLower(InstanceStateProcessing):
|
||||
|
|
@ -182,7 +182,7 @@ func CreateInstanceWaitHandler(
|
|||
default:
|
||||
tflog.Info(
|
||||
ctx, "Wait (create) received unknown status", map[string]interface{}{
|
||||
"instanceId": instanceId,
|
||||
"instanceId": instanceID,
|
||||
"status": s.Status,
|
||||
},
|
||||
)
|
||||
|
|
@ -197,22 +197,22 @@ func CreateInstanceWaitHandler(
|
|||
func UpdateInstanceWaitHandler(
|
||||
ctx context.Context,
|
||||
a APIClientInterface,
|
||||
projectId, instanceId, region string,
|
||||
projectID, instanceID, region string,
|
||||
) *wait.AsyncActionHandler[sqlserverflex.GetInstanceResponse] {
|
||||
handler := wait.New(
|
||||
func() (waitFinished bool, response *sqlserverflex.GetInstanceResponse, err error) {
|
||||
s, err := a.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
|
||||
s, err := a.GetInstanceRequest(ctx, projectID, region, instanceID).Execute()
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
if s == nil || s.Id != instanceId {
|
||||
if s == nil || s.Id != instanceID {
|
||||
return false, nil, nil
|
||||
}
|
||||
switch strings.ToLower(string(s.Status)) {
|
||||
case strings.ToLower(InstanceStateSuccess):
|
||||
return true, s, nil
|
||||
case strings.ToLower(InstanceStateUnknown), strings.ToLower(InstanceStateFailed):
|
||||
return true, s, fmt.Errorf("update failed for instance with id %s", instanceId)
|
||||
return true, s, fmt.Errorf("update failed for instance with id %s", instanceID)
|
||||
case strings.ToLower(InstanceStatePending), strings.ToLower(InstanceStateProcessing):
|
||||
tflog.Info(
|
||||
ctx, "request is being handled", map[string]interface{}{
|
||||
|
|
@ -223,7 +223,7 @@ func UpdateInstanceWaitHandler(
|
|||
default:
|
||||
tflog.Info(
|
||||
ctx, "Wait (update) received unknown status", map[string]interface{}{
|
||||
"instanceId": instanceId,
|
||||
"instanceId": instanceID,
|
||||
"status": s.Status,
|
||||
},
|
||||
)
|
||||
|
|
@ -238,11 +238,11 @@ func UpdateInstanceWaitHandler(
|
|||
func DeleteInstanceWaitHandler(
|
||||
ctx context.Context,
|
||||
a APIClientInterface,
|
||||
projectId, instanceId, region string,
|
||||
projectID, instanceID, region string,
|
||||
) *wait.AsyncActionHandler[sqlserverflex.GetInstanceResponse] {
|
||||
handler := wait.New(
|
||||
func() (waitFinished bool, response *sqlserverflex.GetInstanceResponse, err error) {
|
||||
s, err := a.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
|
||||
s, err := a.GetInstanceRequest(ctx, projectID, region, instanceID).Execute()
|
||||
if err == nil {
|
||||
return false, s, nil
|
||||
}
|
||||
|
|
@ -265,11 +265,11 @@ func DeleteInstanceWaitHandler(
|
|||
func CreateDatabaseWaitHandler(
|
||||
ctx context.Context,
|
||||
a APIClientInterface,
|
||||
projectId, instanceId, region, databaseName string,
|
||||
projectID, instanceID, region, databaseName string,
|
||||
) *wait.AsyncActionHandler[sqlserverflex.GetDatabaseResponse] {
|
||||
handler := wait.New(
|
||||
func() (waitFinished bool, response *sqlserverflex.GetDatabaseResponse, err error) {
|
||||
s, err := a.GetDatabaseRequest(ctx, projectId, region, instanceId, databaseName).Execute()
|
||||
s, err := a.GetDatabaseRequest(ctx, projectID, region, instanceID, databaseName).Execute()
|
||||
if err != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(err, &oapiErr)
|
||||
|
|
@ -297,12 +297,12 @@ func CreateDatabaseWaitHandler(
|
|||
func CreateUserWaitHandler(
|
||||
ctx context.Context,
|
||||
a APIClientInterface,
|
||||
projectId, instanceId, region string,
|
||||
userId int64,
|
||||
projectID, instanceID, region string,
|
||||
userID int64,
|
||||
) *wait.AsyncActionHandler[sqlserverflex.GetUserResponse] {
|
||||
handler := wait.New(
|
||||
func() (waitFinished bool, response *sqlserverflex.GetUserResponse, err error) {
|
||||
s, err := a.GetUserRequest(ctx, projectId, region, instanceId, userId).Execute()
|
||||
s, err := a.GetUserRequest(ctx, projectID, region, instanceID, userID).Execute()
|
||||
if err != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(err, &oapiErr)
|
||||
|
|
@ -324,7 +324,7 @@ func CreateUserWaitHandler(
|
|||
func WaitForUserWaitHandler(
|
||||
ctx context.Context,
|
||||
a APIClientInterface,
|
||||
projectId, instanceId, region, userName string,
|
||||
projectID, instanceID, region, userName string,
|
||||
) *wait.AsyncActionHandler[sqlserverflex.ListUserResponse] {
|
||||
startTime := time.Now()
|
||||
timeOut := 2 * time.Minute
|
||||
|
|
@ -334,7 +334,7 @@ func WaitForUserWaitHandler(
|
|||
if time.Since(startTime) > timeOut {
|
||||
return false, nil, errors.New("ran into timeout")
|
||||
}
|
||||
s, err := a.ListUsersRequest(ctx, projectId, region, instanceId).Size(100).Execute()
|
||||
s, err := a.ListUsersRequest(ctx, projectID, region, instanceID).Size(100).Execute()
|
||||
if err != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(err, &oapiErr)
|
||||
|
|
@ -376,12 +376,12 @@ func WaitForUserWaitHandler(
|
|||
func DeleteUserWaitHandler(
|
||||
ctx context.Context,
|
||||
a APIClientInterface,
|
||||
projectId, region, instanceId string,
|
||||
userId int64,
|
||||
projectID, region, instanceID string,
|
||||
userID int64,
|
||||
) *wait.AsyncActionHandler[struct{}] {
|
||||
handler := wait.New(
|
||||
func() (waitFinished bool, response *struct{}, err error) {
|
||||
_, err = a.GetUserRequest(ctx, projectId, region, instanceId, userId).Execute()
|
||||
_, err = a.GetUserRequest(ctx, projectID, region, instanceID, userID).Execute()
|
||||
if err == nil {
|
||||
return false, nil, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue