Skip to content

Commit 6c1a1ae

Browse files
authored
Improving waiters tests in git package
1 parent b9038ea commit 6c1a1ae

File tree

2 files changed

+10
-28
lines changed

2 files changed

+10
-28
lines changed

services/git/wait/wait.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ const (
1717

1818
// APIClientInterface Interfaces needed for tests
1919
type APIClientInterface interface {
20-
GetGitExecute(ctx context.Context, projectId string, instanceId string) (*git.Instance, error)
20+
GetInstanceExecute(ctx context.Context, projectId string, instanceId string) (*git.Instance, error)
2121
}
2222

2323
func CreateGitInstanceWaitHandler(ctx context.Context, a APIClientInterface, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] {
2424
handler := wait.New(func() (waitFinished bool, response *git.Instance, err error) {
25-
instance, err := a.GetGitExecute(ctx, projectId, instanceId)
25+
instance, err := a.GetInstanceExecute(ctx, projectId, instanceId)
2626
if err != nil {
2727
return false, nil, err
2828
}
@@ -43,7 +43,7 @@ func CreateGitInstanceWaitHandler(ctx context.Context, a APIClientInterface, pro
4343

4444
func DeleteGitInstanceWaitHandler(ctx context.Context, a APIClientInterface, projectId, instanceId string) *wait.AsyncActionHandler[git.Instance] {
4545
handler := wait.New(func() (waitFinished bool, response *git.Instance, err error) {
46-
instance, err := a.GetGitExecute(ctx, projectId, instanceId)
46+
instance, err := a.GetInstanceExecute(ctx, projectId, instanceId)
4747
if err != nil {
4848
return false, nil, err
4949
}

services/git/wait/wait_test.go

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ import (
1414
)
1515

1616
type apiClientMocked struct {
17-
desc string
1817
getFails bool
1918
returnInstance bool
20-
wantErr bool
2119
projectId string
2220
instanceId string
2321
getGitResponse *git.Instance
2422
}
2523

26-
func (a *apiClientMocked) GetGitExecute(_ context.Context, _, _ string) (*git.Instance, error) {
24+
func (a *apiClientMocked) GetInstanceExecute(_ context.Context, _, _ string) (*git.Instance, error) {
2725
if a.getFails {
2826
return nil, &oapierror.GenericOpenAPIError{
2927
StatusCode: http.StatusInternalServerError,
@@ -32,14 +30,7 @@ func (a *apiClientMocked) GetGitExecute(_ context.Context, _, _ string) (*git.In
3230
if !a.returnInstance {
3331
return nil, nil
3432
}
35-
return &git.Instance{
36-
Created: a.getGitResponse.Created,
37-
Id: a.getGitResponse.Id,
38-
Name: a.getGitResponse.Name,
39-
State: a.getGitResponse.State,
40-
Url: a.getGitResponse.Url,
41-
Version: a.getGitResponse.Version,
42-
}, nil
33+
return a.getGitResponse, nil
4334
}
4435

4536
var PROJECT_ID = uuid.New().String()
@@ -74,7 +65,7 @@ func TestCreateGitInstanceWaitHandler(t *testing.T) {
7465
},
7566
},
7667
{
77-
desc: "Creation of an instance Failed With Error",
68+
desc: "Creation of an instance failed with error",
7869
getFails: true,
7970
wantErr: true,
8071
wantResp: false,
@@ -93,7 +84,7 @@ func TestCreateGitInstanceWaitHandler(t *testing.T) {
9384
{
9485
desc: "Creation of an instance with response failed and without error",
9586
getFails: false,
96-
wantErr: false,
87+
wantErr: true,
9788
wantResp: true,
9889
projectId: uuid.New().String(),
9990
instanceId: INSTANCE_ID,
@@ -102,7 +93,7 @@ func TestCreateGitInstanceWaitHandler(t *testing.T) {
10293
Created: utils.Ptr(time.Now()),
10394
Id: utils.Ptr(INSTANCE_ID),
10495
Name: utils.Ptr("instance-test"),
105-
State: utils.Ptr(InstanceStateReady),
96+
State: utils.Ptr(InstanceStateError),
10697
Url: utils.Ptr("https://testing.git.onstackit.cloud"),
10798
Version: utils.Ptr("v1.6.0"),
10899
},
@@ -144,24 +135,15 @@ func TestCreateGitInstanceWaitHandler(t *testing.T) {
144135
for _, tt := range tests {
145136
t.Run(tt.desc, func(t *testing.T) {
146137
apiClient := &apiClientMocked{
147-
desc: tt.desc,
148138
getFails: tt.getFails,
149-
wantErr: tt.wantErr,
150139
projectId: tt.projectId,
151140
instanceId: tt.instanceId,
152141
getGitResponse: tt.getGitResponse,
153142
returnInstance: tt.returnInstance,
154143
}
155144
var instanceWanted *git.Instance
156145
if tt.wantResp {
157-
instanceWanted = &git.Instance{
158-
Created: tt.getGitResponse.Created,
159-
Id: tt.getGitResponse.Id,
160-
Name: tt.getGitResponse.Name,
161-
State: tt.getGitResponse.State,
162-
Url: tt.getGitResponse.Url,
163-
Version: tt.getGitResponse.Version,
164-
}
146+
instanceWanted = tt.getGitResponse
165147
}
166148

167149
handler := CreateGitInstanceWaitHandler(context.Background(), apiClient, apiClient.projectId, apiClient.instanceId)
@@ -208,7 +190,7 @@ func TestDeleteGitInstanceWaitHandler(t *testing.T) {
208190
},
209191
},
210192
{
211-
desc: "Instance deletion succesfull",
193+
desc: "Instance deletion succesful",
212194
wantErr: false,
213195
getFails: false,
214196
wantReturnedInstance: false,

0 commit comments

Comments
 (0)