Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Avarei committed Jun 7, 2024
1 parent fd5c88b commit 3b8ef20
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
20 changes: 10 additions & 10 deletions internal/controller/disposablerequest/disposablerequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ func httpDisposableRequest(rm ...httpDisposableRequestModifier) *v1alpha2.Dispos
return r
}

type MockSendRequestFn func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error)
type MockSendRequestFn func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error)

type MockHttpClient struct {
MockSendRequest MockSendRequestFn
}

func (c *MockHttpClient) SendRequest(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
return c.MockSendRequest(ctx, method, url, body, headers, skipTLSVerify)
func (c *MockHttpClient) SendRequest(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return c.MockSendRequest(ctx, method, url, body, headers)
}

type notHttpDisposableRequest struct {
Expand Down Expand Up @@ -143,7 +143,7 @@ func Test_httpExternal_Create(t *testing.T) {
"DisposableRequestFailed": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, errBoom
},
},
Expand All @@ -161,7 +161,7 @@ func Test_httpExternal_Create(t *testing.T) {
"Success": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, nil
},
},
Expand Down Expand Up @@ -219,7 +219,7 @@ func Test_httpExternal_Update(t *testing.T) {
"DisposableRequestFailed": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, errBoom
},
},
Expand All @@ -236,7 +236,7 @@ func Test_httpExternal_Update(t *testing.T) {
"Success": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, nil
},
},
Expand Down Expand Up @@ -290,7 +290,7 @@ func Test_deployAction(t *testing.T) {
"SuccessUpdateStatusRequestFailure": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, errors.Errorf(utils.ErrInvalidURL, "invalid-url")
},
},
Expand Down Expand Up @@ -318,7 +318,7 @@ func Test_deployAction(t *testing.T) {
"SuccessUpdateStatusCodeError": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{
HttpResponse: httpClient.HttpResponse{
StatusCode: 400,
Expand Down Expand Up @@ -356,7 +356,7 @@ func Test_deployAction(t *testing.T) {
"SuccessUpdateStatusSuccessfulRequest": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{
HttpResponse: httpClient.HttpResponse{
StatusCode: 200,
Expand Down
14 changes: 7 additions & 7 deletions internal/controller/request/observe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Test_isUpToDate(t *testing.T) {
"ObjectNotFoundEmptyBody": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, nil
},
},
Expand All @@ -54,7 +54,7 @@ func Test_isUpToDate(t *testing.T) {
"ObjectNotFoundPostFailed": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, nil
},
},
Expand All @@ -73,7 +73,7 @@ func Test_isUpToDate(t *testing.T) {
"ObjectNotFound404StatusCode": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, nil
},
},
Expand All @@ -91,7 +91,7 @@ func Test_isUpToDate(t *testing.T) {
"FailBodyNotJSON": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{
HttpResponse: httpClient.HttpResponse{
Body: "not a JSON",
Expand All @@ -113,7 +113,7 @@ func Test_isUpToDate(t *testing.T) {
"SuccessNotSynced": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{
HttpResponse: httpClient.HttpResponse{
Body: `{"username":"old_name"}`,
Expand Down Expand Up @@ -147,7 +147,7 @@ func Test_isUpToDate(t *testing.T) {
"SuccessNoPUTMapping": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{
HttpResponse: httpClient.HttpResponse{
Body: `{"username":"old_name"}`,
Expand Down Expand Up @@ -187,7 +187,7 @@ func Test_isUpToDate(t *testing.T) {
"SuccessJSONBody": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{
HttpResponse: httpClient.HttpResponse{
Body: `{"username":"john_doe_new_username"}`,
Expand Down
18 changes: 9 additions & 9 deletions internal/controller/request/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ type notHttpRequest struct {
resource.Managed
}

type MockSendRequestFn func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error)
type MockSendRequestFn func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error)

type MockHttpClient struct {
MockSendRequest MockSendRequestFn
}

func (c *MockHttpClient) SendRequest(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
return c.MockSendRequest(ctx, method, url, body, headers, skipTLSVerify)
func (c *MockHttpClient) SendRequest(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return c.MockSendRequest(ctx, method, url, body, headers)
}

type MockSetRequestStatusFn func() error
Expand Down Expand Up @@ -126,7 +126,7 @@ func Test_httpExternal_Create(t *testing.T) {
"RequestFailed": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, errBoom
},
},
Expand All @@ -143,7 +143,7 @@ func Test_httpExternal_Create(t *testing.T) {
"Success": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, nil
},
},
Expand Down Expand Up @@ -201,7 +201,7 @@ func Test_httpExternal_Update(t *testing.T) {
"RequestFailed": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, errBoom
},
},
Expand All @@ -218,7 +218,7 @@ func Test_httpExternal_Update(t *testing.T) {
"Success": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, nil
},
},
Expand Down Expand Up @@ -276,7 +276,7 @@ func Test_httpExternal_Delete(t *testing.T) {
"RequestFailed": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, errBoom
},
},
Expand All @@ -293,7 +293,7 @@ func Test_httpExternal_Delete(t *testing.T) {
"Success": {
args: args{
http: &MockHttpClient{
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data, skipTLSVerify bool) (resp httpClient.HttpDetails, err error) {
MockSendRequest: func(ctx context.Context, method string, url string, body httpClient.Data, headers httpClient.Data) (resp httpClient.HttpDetails, err error) {
return httpClient.HttpDetails{}, nil
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ func Test_generateRequestObject(t *testing.T) {
"body": map[string]any{"id": "123"},
"statusCode": float64(200),
},
"tlsSecretRef": map[string]any{
"name": "",
"namespace": "",
},
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions internal/json/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ func Test_StructToMap(t *testing.T) {
"baseUrl": "https://api.example.com/users",
"body": `{"username": "john_doe", "email": "john.doe@example.com"}`,
},
"tlsSecretRef": map[string]any{
"name": "",
"namespace": "",
},
},
errMessage: "",
},
Expand Down

0 comments on commit 3b8ef20

Please sign in to comment.