mirror of
https://github.com/elyby/chrly.git
synced 2025-02-09 02:06:28 +05:30
#1: Improve uuidToTextures method, organize tests
This commit is contained in:
parent
7db4d27fba
commit
44f3ee7413
@ -55,8 +55,13 @@ func UsernamesToUuids(usernames []string) ([]*ProfileInfo, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UuidToTextures(uuid string) (*SignedTexturesResponse, error) {
|
func UuidToTextures(uuid string, signed bool) (*SignedTexturesResponse, error) {
|
||||||
request, err := http.NewRequest("GET", "https://sessionserver.mojang.com/session/minecraft/profile/"+uuid, nil)
|
url := "https://sessionserver.mojang.com/session/minecraft/profile/" + uuid
|
||||||
|
if signed {
|
||||||
|
url += "?unsigned=false"
|
||||||
|
}
|
||||||
|
|
||||||
|
request, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,8 @@ import (
|
|||||||
"gopkg.in/h2non/gock.v1"
|
"gopkg.in/h2non/gock.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUsernamesToUuidsCorrectResponse(t *testing.T) {
|
func TestUsernamesToUuids(t *testing.T) {
|
||||||
|
t.Run("exchange usernames to uuids", func(t *testing.T) {
|
||||||
assert := testify.New(t)
|
assert := testify.New(t)
|
||||||
|
|
||||||
defer gock.Off()
|
defer gock.Off()
|
||||||
@ -48,9 +49,9 @@ func TestUsernamesToUuidsCorrectResponse(t *testing.T) {
|
|||||||
assert.False(result[1].IsLegacy)
|
assert.False(result[1].IsLegacy)
|
||||||
assert.False(result[1].IsDemo)
|
assert.False(result[1].IsDemo)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestUsernamesToUuidsTooManyRequests(t *testing.T) {
|
t.Run("handle too many requests error", func(t *testing.T) {
|
||||||
assert := testify.New(t)
|
assert := testify.New(t)
|
||||||
|
|
||||||
defer gock.Off()
|
defer gock.Off()
|
||||||
@ -71,9 +72,11 @@ func TestUsernamesToUuidsTooManyRequests(t *testing.T) {
|
|||||||
assert.Nil(result)
|
assert.Nil(result)
|
||||||
assert.IsType(&TooManyRequestsError{}, err)
|
assert.IsType(&TooManyRequestsError{}, err)
|
||||||
assert.EqualError(err, "Too Many Requests")
|
assert.EqualError(err, "Too Many Requests")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUuidToTexturesCorrectResponse(t *testing.T) {
|
func TestUuidToTextures(t *testing.T) {
|
||||||
|
t.Run("obtain not signed textures", func(t *testing.T) {
|
||||||
assert := testify.New(t)
|
assert := testify.New(t)
|
||||||
|
|
||||||
defer gock.Off()
|
defer gock.Off()
|
||||||
@ -96,17 +99,54 @@ func TestUuidToTexturesCorrectResponse(t *testing.T) {
|
|||||||
|
|
||||||
HttpClient = client
|
HttpClient = client
|
||||||
|
|
||||||
result, err := UuidToTextures("4566e69fc90748ee8d71d7ba5aa00d20")
|
result, err := UuidToTextures("4566e69fc90748ee8d71d7ba5aa00d20", false)
|
||||||
if assert.NoError(err) {
|
if assert.NoError(err) {
|
||||||
assert.Equal("4566e69fc90748ee8d71d7ba5aa00d20", result.Id)
|
assert.Equal("4566e69fc90748ee8d71d7ba5aa00d20", result.Id)
|
||||||
assert.Equal("Thinkofdeath", result.Name)
|
assert.Equal("Thinkofdeath", result.Name)
|
||||||
assert.Equal(1, len(result.Props))
|
assert.Equal(1, len(result.Props))
|
||||||
assert.Equal("textures", result.Props[0].Name)
|
assert.Equal("textures", result.Props[0].Name)
|
||||||
assert.Equal(476, len(result.Props[0].Value))
|
assert.Equal(476, len(result.Props[0].Value))
|
||||||
|
assert.Equal("", result.Props[0].Signature)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestUuidToTexturesTooManyRequests(t *testing.T) {
|
t.Run("obtain signed textures", func(t *testing.T) {
|
||||||
|
assert := testify.New(t)
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
gock.New("https://sessionserver.mojang.com").
|
||||||
|
Get("/session/minecraft/profile/4566e69fc90748ee8d71d7ba5aa00d20").
|
||||||
|
MatchParam("unsigned", "false").
|
||||||
|
Reply(200).
|
||||||
|
JSON(map[string]interface{}{
|
||||||
|
"id": "4566e69fc90748ee8d71d7ba5aa00d20",
|
||||||
|
"name": "Thinkofdeath",
|
||||||
|
"properties": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": "textures",
|
||||||
|
"signature": "signature string",
|
||||||
|
"value": "eyJ0aW1lc3RhbXAiOjE1NDMxMDczMDExODUsInByb2ZpbGVJZCI6IjQ1NjZlNjlmYzkwNzQ4ZWU4ZDcxZDdiYTVhYTAwZDIwIiwicHJvZmlsZU5hbWUiOiJUaGlua29mZGVhdGgiLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzRkMWUwOGIwYmI3ZTlmNTkwYWYyNzc1ODEyNWJiZWQxNzc4YWM2Y2VmNzI5YWVkZmNiOTYxM2U5OTExYWU3NSJ9LCJDQVBFIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjBjYzA4ODQwNzAwNDQ3MzIyZDk1M2EwMmI5NjVmMWQ2NWExM2E2MDNiZjY0YjE3YzgwM2MyMTQ0NmZlMTYzNSJ9fX0=",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
gock.InterceptClient(client)
|
||||||
|
|
||||||
|
HttpClient = client
|
||||||
|
|
||||||
|
result, err := UuidToTextures("4566e69fc90748ee8d71d7ba5aa00d20", true)
|
||||||
|
if assert.NoError(err) {
|
||||||
|
assert.Equal("4566e69fc90748ee8d71d7ba5aa00d20", result.Id)
|
||||||
|
assert.Equal("Thinkofdeath", result.Name)
|
||||||
|
assert.Equal(1, len(result.Props))
|
||||||
|
assert.Equal("textures", result.Props[0].Name)
|
||||||
|
assert.Equal(476, len(result.Props[0].Value))
|
||||||
|
assert.Equal("signature string", result.Props[0].Signature)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("handle too many requests error", func(t *testing.T) {
|
||||||
assert := testify.New(t)
|
assert := testify.New(t)
|
||||||
|
|
||||||
defer gock.Off()
|
defer gock.Off()
|
||||||
@ -123,8 +163,9 @@ func TestUuidToTexturesTooManyRequests(t *testing.T) {
|
|||||||
|
|
||||||
HttpClient = client
|
HttpClient = client
|
||||||
|
|
||||||
result, err := UuidToTextures("4566e69fc90748ee8d71d7ba5aa00d20")
|
result, err := UuidToTextures("4566e69fc90748ee8d71d7ba5aa00d20", false)
|
||||||
assert.Nil(result)
|
assert.Nil(result)
|
||||||
assert.IsType(&TooManyRequestsError{}, err)
|
assert.IsType(&TooManyRequestsError{}, err)
|
||||||
assert.EqualError(err, "Too Many Requests")
|
assert.EqualError(err, "Too Many Requests")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user