Refactored test utils in VK module
This commit is contained in:
parent
d5f9a495b7
commit
121bb9fc9c
6 changed files with 124 additions and 112 deletions
46
internal/vk/test_ctx.go
Normal file
46
internal/vk/test_ctx.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package vk
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http/httptest"
|
||||
)
|
||||
|
||||
type testCtx struct {
|
||||
handler *Handler
|
||||
recorder *httptest.ResponseRecorder
|
||||
sender *testSender
|
||||
logBuf *bytes.Buffer
|
||||
}
|
||||
|
||||
func getTestHandlerCtx() testCtx {
|
||||
sender := &testSender{}
|
||||
buf := &bytes.Buffer{}
|
||||
return testCtx{
|
||||
logBuf: buf,
|
||||
handler: &Handler{
|
||||
SecretKey: "sec",
|
||||
GroupId: 10,
|
||||
ConfirmationString: "con",
|
||||
Sender: sender,
|
||||
Logger: log.New(buf, "", 0),
|
||||
InfoFetcher: &testInfoFetcher{},
|
||||
Cache: &testCache{
|
||||
table: map[string]string{
|
||||
"good": "good",
|
||||
},
|
||||
},
|
||||
},
|
||||
sender: sender,
|
||||
recorder: httptest.NewRecorder(),
|
||||
}
|
||||
}
|
||||
|
||||
func getTestRequestCtx(msgReq *messageRequest, recorder *httptest.ResponseRecorder) *gin.Context {
|
||||
ctx, _ := gin.CreateTestContext(recorder)
|
||||
body, _ := json.Marshal(msgReq)
|
||||
ctx.Request = httptest.NewRequest("POST", "/", bytes.NewReader(body))
|
||||
return ctx
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue