Skip to content

Commit 4993201

Browse files
author
jp
committed
added http mocks to the testing + Ihttoptions interface
1 parent 69ae672 commit 4993201

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package mock_executor
2+
3+
import (
4+
"soarca/utils/http"
5+
6+
"github.com/stretchr/testify/mock"
7+
)
8+
9+
type MockHttpOptions struct {
10+
mock.Mock
11+
}
12+
13+
type MockHttpRequest struct {
14+
mock.Mock
15+
}
16+
17+
func (httpOptions *MockHttpOptions) ExtractUrl() (string, error) {
18+
args := httpOptions.Called()
19+
return args.String(0), args.Error(1)
20+
}
21+
22+
func (httpOptions *MockHttpRequest) Request(options http.HttpOptions) ([]byte, error) {
23+
args := httpOptions.Called(options)
24+
return args.Get(0).([]byte), args.Error(1)
25+
}

utils/http/http.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ type HttpOptions struct {
2727
Auth *cacao.AuthenticationInformation
2828
}
2929

30+
type IHttpOptions interface {
31+
ExtractUrl() (string, error)
32+
}
3033
type IHttpRequest interface {
31-
Request() ([]byte, error)
34+
Request(httpOptions HttpOptions) ([]byte, error)
3235
}
3336

3437
type HttpRequest struct{}

0 commit comments

Comments
 (0)