2017-08-20 03:52:42 +05:30
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-04-28 03:13:22 +05:30
|
|
|
"time"
|
2017-08-20 03:52:42 +05:30
|
|
|
|
2019-04-28 03:13:22 +05:30
|
|
|
"github.com/elyby/chrly/api/mojang"
|
|
|
|
|
|
|
|
"github.com/elyby/chrly/tests"
|
2017-08-20 03:52:42 +05:30
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
testify "github.com/stretchr/testify/assert"
|
|
|
|
|
2018-02-16 02:43:57 +05:30
|
|
|
"github.com/elyby/chrly/interfaces/mock_interfaces"
|
|
|
|
"github.com/elyby/chrly/interfaces/mock_wd"
|
2017-08-20 03:52:42 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseUsername(t *testing.T) {
|
|
|
|
assert := testify.New(t)
|
|
|
|
assert.Equal("test", parseUsername("test.png"), "Function should trim .png at end")
|
|
|
|
assert.Equal("test", parseUsername("test"), "Function should return string itself, if it not contains .png at end")
|
|
|
|
}
|
|
|
|
|
2018-01-23 02:46:42 +05:30
|
|
|
type mocks struct {
|
|
|
|
Skins *mock_interfaces.MockSkinsRepository
|
|
|
|
Capes *mock_interfaces.MockCapesRepository
|
2019-04-28 03:13:22 +05:30
|
|
|
Queue *tests.MojangTexturesQueueMock
|
2018-01-23 21:13:37 +05:30
|
|
|
Auth *mock_interfaces.MockAuthChecker
|
2018-01-23 02:46:42 +05:30
|
|
|
Log *mock_wd.MockWatchdog
|
|
|
|
}
|
|
|
|
|
2017-08-20 03:52:42 +05:30
|
|
|
func setupMocks(ctrl *gomock.Controller) (
|
|
|
|
*Config,
|
2018-01-23 02:46:42 +05:30
|
|
|
*mocks,
|
2017-08-20 03:52:42 +05:30
|
|
|
) {
|
|
|
|
skinsRepo := mock_interfaces.NewMockSkinsRepository(ctrl)
|
|
|
|
capesRepo := mock_interfaces.NewMockCapesRepository(ctrl)
|
2018-01-23 21:13:37 +05:30
|
|
|
authChecker := mock_interfaces.NewMockAuthChecker(ctrl)
|
2017-08-20 03:52:42 +05:30
|
|
|
wd := mock_wd.NewMockWatchdog(ctrl)
|
2019-04-28 03:13:22 +05:30
|
|
|
texturesQueue := &tests.MojangTexturesQueueMock{}
|
2017-08-20 03:52:42 +05:30
|
|
|
|
|
|
|
return &Config{
|
2019-04-28 03:13:22 +05:30
|
|
|
SkinsRepo: skinsRepo,
|
|
|
|
CapesRepo: capesRepo,
|
|
|
|
Auth: authChecker,
|
|
|
|
MojangTexturesQueue: texturesQueue,
|
|
|
|
Logger: wd,
|
2018-01-23 02:46:42 +05:30
|
|
|
}, &mocks{
|
|
|
|
Skins: skinsRepo,
|
|
|
|
Capes: capesRepo,
|
2018-01-23 21:13:37 +05:30
|
|
|
Auth: authChecker,
|
2019-04-28 03:13:22 +05:30
|
|
|
Queue: texturesQueue,
|
2018-01-23 02:46:42 +05:30
|
|
|
Log: wd,
|
|
|
|
}
|
2017-08-20 03:52:42 +05:30
|
|
|
}
|
2019-04-28 03:13:22 +05:30
|
|
|
|
|
|
|
func createTexturesResponse(includeSkin bool, includeCape bool) *mojang.SignedTexturesResponse {
|
|
|
|
timeZone, _ := time.LoadLocation("Europe/Minsk")
|
|
|
|
textures := &mojang.TexturesProp{
|
|
|
|
Timestamp: time.Date(2019, 4, 27, 23, 56, 12, 0, timeZone).Unix(),
|
|
|
|
ProfileID: "00000000000000000000000000000000",
|
|
|
|
ProfileName: "mock_user",
|
|
|
|
Textures: &mojang.TexturesResponse{},
|
|
|
|
}
|
|
|
|
|
|
|
|
if includeSkin {
|
|
|
|
textures.Textures.Skin = &mojang.SkinTexturesResponse{
|
|
|
|
Url: "http://mojang/skin.png",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if includeCape {
|
|
|
|
textures.Textures.Cape = &mojang.CapeTexturesResponse{
|
|
|
|
Url: "http://mojang/cape.png",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
response := &mojang.SignedTexturesResponse{
|
|
|
|
Id: "00000000000000000000000000000000",
|
|
|
|
Name: "mock_user",
|
|
|
|
Props: []*mojang.Property{
|
|
|
|
{
|
|
|
|
Name: "textures",
|
|
|
|
Value: mojang.EncodeTextures(textures),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return response
|
|
|
|
}
|