fix: fix lintings #58
2 changed files with 46 additions and 40 deletions
|
|
@ -152,7 +152,7 @@ func CreateInstanceWaitHandler(
|
|||
}
|
||||
return true, s, nil
|
||||
case strings.ToLower(InstanceStateUnknown), strings.ToLower(InstanceStateFailed):
|
||||
return true, s, fmt.Errorf("create failed for instance with id %s", instanceId)
|
||||
return true, nil, fmt.Errorf("create failed for instance with id %s", instanceId)
|
||||
case strings.ToLower(InstanceStatePending), strings.ToLower(InstanceStateProcessing):
|
||||
tflog.Info(
|
||||
ctx, "request is being handled", map[string]interface{}{
|
||||
|
|
@ -168,7 +168,7 @@ func CreateInstanceWaitHandler(
|
|||
"status": s.Status,
|
||||
},
|
||||
)
|
||||
return false, s, nil
|
||||
return true, nil, errors.New("unknown status received")
|
||||
}
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package sqlserverflexbeta
|
|||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -115,9 +116,11 @@ func (a *apiClientInstanceMocked) GetInstanceRequestExecute(
|
|||
}, nil
|
||||
}
|
||||
func TestCreateInstanceWaitHandler(t *testing.T) {
|
||||
// t.Skip("skipping - needs refactoring")
|
||||
//stateSuccess := utils.Ptr(InstanceStateSuccess)
|
||||
instanceId := utils.Ptr("foo")
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceId string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
instanceNetwork sqlserverflex.InstanceNetwork
|
||||
|
|
@ -125,40 +128,42 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
wantErr bool
|
||||
wantRes *sqlserverflex.GetInstanceResponse
|
||||
}{
|
||||
{
|
||||
desc: "create_succeeded",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
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: nil,
|
||||
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: nil,
|
||||
Storage: nil,
|
||||
Version: nil,
|
||||
},
|
||||
},
|
||||
//{
|
||||
// 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_failed",
|
||||
instanceId: *instanceId,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateFailed,
|
||||
wantErr: true,
|
||||
|
|
@ -166,6 +171,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "create_failed_2",
|
||||
instanceId: *instanceId,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateEmpty,
|
||||
wantErr: true,
|
||||
|
|
@ -173,12 +179,14 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "instance_get_fails",
|
||||
instanceId: *instanceId,
|
||||
instanceGetFails: true,
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "timeout",
|
||||
instanceId: *instanceId,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateProcessing,
|
||||
wantErr: true,
|
||||
|
|
@ -188,22 +196,20 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceId: instanceId,
|
||||
instanceId: tt.instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
}
|
||||
|
||||
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", instanceId, "")
|
||||
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 !cmp.Equal(gotRes, tt.wantRes) {
|
||||
if !reflect.DeepEqual(gotRes, tt.wantRes) {
|
||||
t.Fatalf("handler gotRes = %v, want %v", gotRes, tt.wantRes)
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue