fix: builder and sdk changes (#81)
## 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>
Co-authored-by: marcel.henselin <marcel.henselin@stackit.cloud>
Reviewed-on: #81
This commit is contained in:
parent
635a9abf20
commit
1033d7e034
145 changed files with 5944 additions and 5298 deletions
|
|
@ -9,160 +9,57 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3beta1api"
|
||||
)
|
||||
|
||||
// Used for testing instance operations
|
||||
type apiClientInstanceMocked struct {
|
||||
instanceId string
|
||||
instanceState string
|
||||
instanceNetwork sqlserverflex.InstanceNetwork
|
||||
instanceIsDeleted bool
|
||||
instanceGetFails bool
|
||||
}
|
||||
|
||||
type ListUsersRequestRequest struct{}
|
||||
|
||||
func (l ListUsersRequestRequest) Page(_ int64) sqlserverflex.ApiListUsersRequestRequest {
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListUsersRequestRequest) Size(_ int64) sqlserverflex.ApiListUsersRequestRequest {
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListUsersRequestRequest) Sort(_ sqlserverflex.UserSort) sqlserverflex.ApiListUsersRequestRequest {
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListUsersRequestRequest) Execute() (*sqlserverflex.ListUserResponse, error) {
|
||||
// TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) ListUsersRequest(
|
||||
_ context.Context,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
) sqlserverflex.ApiListUsersRequestRequest {
|
||||
return ListUsersRequestRequest{}
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) ListRolesRequestExecute(
|
||||
_ context.Context,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
) (*sqlserverflex.ListRolesResponse, error) {
|
||||
return &sqlserverflex.ListRolesResponse{
|
||||
Roles: &[]string{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) ListUsersRequestExecute(
|
||||
_ context.Context,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
) (*sqlserverflex.ListUserResponse, error) {
|
||||
return &sqlserverflex.ListUserResponse{
|
||||
Pagination: nil,
|
||||
Users: nil,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) GetDatabaseRequestExecute(
|
||||
_ context.Context,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
) (*sqlserverflex.GetDatabaseResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) GetUserRequestExecute(
|
||||
_ context.Context,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
_ int64,
|
||||
) (*sqlserverflex.GetUserResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) GetInstanceRequestExecute(
|
||||
_ context.Context,
|
||||
_, _, _ string,
|
||||
) (*sqlserverflex.GetInstanceResponse, error) {
|
||||
if a.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
if a.instanceIsDeleted {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 404,
|
||||
}
|
||||
}
|
||||
|
||||
return &sqlserverflex.GetInstanceResponse{
|
||||
Id: &a.instanceId,
|
||||
Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(&a.instanceState),
|
||||
Network: &a.instanceNetwork,
|
||||
}, nil
|
||||
}
|
||||
func TestCreateInstanceWaitHandler(t *testing.T) {
|
||||
instanceId := utils.Ptr("foo")
|
||||
instanceID := utils.Ptr("foo")
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceId string
|
||||
instanceID string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
instanceNetwork sqlserverflex.InstanceNetwork
|
||||
instanceNetwork v3beta1api.InstanceNetwork
|
||||
usersGetErrorStatus int
|
||||
wantErr bool
|
||||
wantRes *sqlserverflex.GetInstanceResponse
|
||||
wantRes *v3beta1api.GetInstanceResponse
|
||||
}{
|
||||
//{
|
||||
// desc: "create_succeeded",
|
||||
// instanceId: *instanceId,
|
||||
// instanceGetFails: false,
|
||||
// instanceState: *stateSuccess,
|
||||
// instanceNetwork: sqlserverflex.InstanceNetwork{
|
||||
// AccessScope: nil,
|
||||
// Acl: nil,
|
||||
// InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
// RouterAddress: utils.Ptr("10.0.0.2"),
|
||||
// },
|
||||
// wantErr: false,
|
||||
// wantRes: &sqlserverflex.GetInstanceResponse{
|
||||
// BackupSchedule: nil,
|
||||
// Edition: nil,
|
||||
// Encryption: nil,
|
||||
// FlavorId: nil,
|
||||
// Id: instanceId,
|
||||
// IsDeletable: nil,
|
||||
// Name: nil,
|
||||
// Network: &sqlserverflex.InstanceNetwork{
|
||||
// AccessScope: nil,
|
||||
// Acl: nil,
|
||||
// InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
// RouterAddress: utils.Ptr("10.0.0.2"),
|
||||
// },
|
||||
// Replicas: nil,
|
||||
// RetentionDays: nil,
|
||||
// Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(stateSuccess),
|
||||
// Storage: nil,
|
||||
// Version: nil,
|
||||
// },
|
||||
// },
|
||||
{
|
||||
desc: "create_succeeded_default_values",
|
||||
instanceID: "instance1",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: v3beta1api.InstanceNetwork{
|
||||
AccessScope: (*v3beta1api.InstanceNetworkAccessScope)(utils.Ptr("PUBLIC")),
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.2"),
|
||||
},
|
||||
wantErr: false,
|
||||
wantRes: &v3beta1api.GetInstanceResponse{
|
||||
BackupSchedule: "",
|
||||
Edition: "",
|
||||
Encryption: nil,
|
||||
FlavorId: "",
|
||||
Id: "instance1",
|
||||
IsDeletable: false,
|
||||
Name: "",
|
||||
Network: v3beta1api.InstanceNetwork{
|
||||
AccessScope: (*v3beta1api.InstanceNetworkAccessScope)(utils.Ptr("PUBLIC")),
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.2"),
|
||||
},
|
||||
Replicas: 0,
|
||||
RetentionDays: 0,
|
||||
Status: v3beta1api.Status(InstanceStateSuccess),
|
||||
Storage: v3beta1api.Storage{},
|
||||
Version: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "create_failed",
|
||||
instanceId: *instanceId,
|
||||
instanceID: *instanceID,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateFailed,
|
||||
wantErr: true,
|
||||
|
|
@ -170,7 +67,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "create_failed_2",
|
||||
instanceId: *instanceId,
|
||||
instanceID: *instanceID,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateEmpty,
|
||||
wantErr: true,
|
||||
|
|
@ -178,14 +75,14 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "instance_get_fails",
|
||||
instanceId: *instanceId,
|
||||
instanceID: *instanceID,
|
||||
instanceGetFails: true,
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "timeout",
|
||||
instanceId: *instanceId,
|
||||
instanceID: *instanceID,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateProcessing,
|
||||
wantErr: true,
|
||||
|
|
@ -195,19 +92,55 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceId: tt.instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
listRolesMock := func(_ v3beta1api.ApiListRolesRequestRequest) (*v3beta1api.ListRolesResponse, error) {
|
||||
return &v3beta1api.ListRolesResponse{
|
||||
Roles: []string{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", tt.instanceId, "")
|
||||
listUsersMock := func(_ v3beta1api.ApiListUsersRequestRequest) (*v3beta1api.ListUserResponse, error) {
|
||||
aux := int64(0)
|
||||
return &v3beta1api.ListUserResponse{
|
||||
Pagination: v3beta1api.Pagination{
|
||||
TotalRows: aux,
|
||||
},
|
||||
Users: []v3beta1api.ListUser{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
mockCall := func(_ v3beta1api.ApiGetInstanceRequestRequest) (*v3beta1api.GetInstanceResponse, error) {
|
||||
if tt.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
return &v3beta1api.GetInstanceResponse{
|
||||
Id: tt.instanceID,
|
||||
Status: v3beta1api.Status(tt.instanceState),
|
||||
Network: tt.instanceNetwork,
|
||||
Storage: v3beta1api.Storage{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
apiClient := v3beta1api.DefaultAPIServiceMock{
|
||||
GetInstanceRequestExecuteMock: &mockCall,
|
||||
ListUsersRequestExecuteMock: &listUsersMock,
|
||||
ListRolesRequestExecuteMock: &listRolesMock,
|
||||
}
|
||||
|
||||
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", tt.instanceID, "")
|
||||
|
||||
gotRes, err := handler.SetTimeout(10 * time.Millisecond).SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background())
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
if diff := cmp.Diff(tt.wantRes, gotRes); diff != "" {
|
||||
t.Errorf("model mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(gotRes, tt.wantRes) {
|
||||
t.Fatalf("handler gotRes = %v, want %v", gotRes, tt.wantRes)
|
||||
}
|
||||
|
|
@ -217,7 +150,6 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateInstanceWaitHandler(t *testing.T) {
|
||||
t.Skip("skipping - needs refactoring")
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceGetFails bool
|
||||
|
|
@ -263,23 +195,35 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
instanceID := "foo-bar"
|
||||
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceId: instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
mockCall := func(_ v3beta1api.ApiGetInstanceRequestRequest) (*v3beta1api.GetInstanceResponse, error) {
|
||||
if tt.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
return &v3beta1api.GetInstanceResponse{
|
||||
Id: instanceID,
|
||||
Status: v3beta1api.Status(tt.instanceState),
|
||||
//Network: tt.instanceNetwork,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var wantRes *sqlserverflex.GetInstanceResponse
|
||||
apiClient := v3beta1api.DefaultAPIServiceMock{
|
||||
GetInstanceRequestExecuteMock: &mockCall,
|
||||
}
|
||||
|
||||
var wantRes *v3beta1api.GetInstanceResponse
|
||||
if tt.wantResp {
|
||||
wantRes = &sqlserverflex.GetInstanceResponse{
|
||||
Id: &instanceId,
|
||||
Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr(tt.instanceState)),
|
||||
wantRes = &v3beta1api.GetInstanceResponse{
|
||||
Id: instanceID,
|
||||
Status: v3beta1api.Status(tt.instanceState),
|
||||
}
|
||||
}
|
||||
|
||||
handler := UpdateInstanceWaitHandler(context.Background(), apiClient, "", instanceId, "")
|
||||
handler := UpdateInstanceWaitHandler(context.Background(), apiClient, "", instanceID, "")
|
||||
|
||||
gotRes, err := handler.SetTimeout(10 * time.Millisecond).SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background())
|
||||
|
||||
|
|
@ -322,16 +266,33 @@ func TestDeleteInstanceWaitHandler(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
instanceID := "foo-bar"
|
||||
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
instanceIsDeleted: tt.instanceState == InstanceStateSuccess,
|
||||
instanceId: instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
mockCall := func(_ v3beta1api.ApiGetInstanceRequestRequest) (*v3beta1api.GetInstanceResponse, error) {
|
||||
if tt.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
if tt.instanceState == InstanceStateSuccess {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 404,
|
||||
}
|
||||
}
|
||||
|
||||
return &v3beta1api.GetInstanceResponse{
|
||||
Id: instanceID,
|
||||
Status: v3beta1api.Status(tt.instanceState),
|
||||
//Network: tt.instanceNetwork,
|
||||
}, nil
|
||||
}
|
||||
|
||||
handler := DeleteInstanceWaitHandler(context.Background(), apiClient, "", instanceId, "")
|
||||
apiClient := v3beta1api.DefaultAPIServiceMock{
|
||||
GetInstanceRequestExecuteMock: &mockCall,
|
||||
}
|
||||
|
||||
handler := DeleteInstanceWaitHandler(context.Background(), apiClient, "", instanceID, "")
|
||||
|
||||
_, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue