mirror of
https://github.com/elyby/chrly.git
synced 2024-12-23 13:40:11 +05:30
Fix tests for worker
This commit is contained in:
parent
c9f6079d90
commit
0c81494559
@ -20,7 +20,7 @@ type UUIDsWorker struct {
|
||||
}
|
||||
|
||||
func (ctx *UUIDsWorker) CreateHandler() *mux.Router {
|
||||
requestEventsMiddleware := CreateRequestEventsMiddleware(ctx.Emitter, "skinsystem")
|
||||
requestEventsMiddleware := CreateRequestEventsMiddleware(ctx.Emitter, "skinsystem") // This prefix should be unified
|
||||
|
||||
router := mux.NewRouter().StrictSlash(true)
|
||||
router.Use(requestEventsMiddleware)
|
||||
@ -39,7 +39,6 @@ func (ctx *UUIDsWorker) GetUUID(response http.ResponseWriter, request *http.Requ
|
||||
username := parseUsername(mux.Vars(request)["username"])
|
||||
profile, err := ctx.UUIDsProvider.GetUuid(username)
|
||||
if err != nil {
|
||||
ctx.Emit("uuids_provider:error", err) // TODO: do I need emitter here?
|
||||
if _, ok := err.(*mojang.TooManyRequestsError); ok {
|
||||
response.WriteHeader(http.StatusTooManyRequests)
|
||||
return
|
||||
|
@ -87,6 +87,8 @@ var getUuidTestsCases = []*uuidsWorkerTestCase{
|
||||
{
|
||||
Name: "Success provider response",
|
||||
BeforeTest: func(suite *uuidsWorkerTestSuite) {
|
||||
suite.Emitter.On("Emit", "skinsystem:before_request", mock.Anything)
|
||||
suite.Emitter.On("Emit", "skinsystem:after_request", mock.Anything, 200)
|
||||
suite.UuidsProvider.On("GetUuid", "mock_username").Return(&mojang.ProfileInfo{
|
||||
Id: "0fcc38620f1845f3a54e1b523c1bd1c7",
|
||||
Name: "mock_username",
|
||||
@ -105,6 +107,8 @@ var getUuidTestsCases = []*uuidsWorkerTestCase{
|
||||
{
|
||||
Name: "Receive empty response from UUIDs provider",
|
||||
BeforeTest: func(suite *uuidsWorkerTestSuite) {
|
||||
suite.Emitter.On("Emit", "skinsystem:before_request", mock.Anything)
|
||||
suite.Emitter.On("Emit", "skinsystem:after_request", mock.Anything, 204)
|
||||
suite.UuidsProvider.On("GetUuid", "mock_username").Return(nil, nil)
|
||||
},
|
||||
AfterTest: func(suite *uuidsWorkerTestSuite, response *http.Response) {
|
||||
@ -116,9 +120,10 @@ var getUuidTestsCases = []*uuidsWorkerTestCase{
|
||||
{
|
||||
Name: "Receive error from UUIDs provider",
|
||||
BeforeTest: func(suite *uuidsWorkerTestSuite) {
|
||||
suite.Emitter.On("Emit", "skinsystem:before_request", mock.Anything)
|
||||
suite.Emitter.On("Emit", "skinsystem:after_request", mock.Anything, 500)
|
||||
err := errors.New("this is an error")
|
||||
suite.UuidsProvider.On("GetUuid", "mock_username").Return(nil, err)
|
||||
suite.Emitter.On("Emit", "uuids_provider:error", err).Times(1)
|
||||
},
|
||||
AfterTest: func(suite *uuidsWorkerTestSuite, response *http.Response) {
|
||||
suite.Equal(500, response.StatusCode)
|
||||
@ -132,9 +137,10 @@ var getUuidTestsCases = []*uuidsWorkerTestCase{
|
||||
{
|
||||
Name: "Receive Too Many Requests from UUIDs provider",
|
||||
BeforeTest: func(suite *uuidsWorkerTestSuite) {
|
||||
suite.Emitter.On("Emit", "skinsystem:before_request", mock.Anything)
|
||||
suite.Emitter.On("Emit", "skinsystem:after_request", mock.Anything, 429)
|
||||
err := &mojang.TooManyRequestsError{}
|
||||
suite.UuidsProvider.On("GetUuid", "mock_username").Return(nil, err)
|
||||
suite.Emitter.On("Emit", "uuids_provider:error", err).Times(1)
|
||||
},
|
||||
AfterTest: func(suite *uuidsWorkerTestSuite, response *http.Response) {
|
||||
suite.Equal(429, response.StatusCode)
|
||||
|
Loading…
Reference in New Issue
Block a user