From 94b930f388a80793c2ceadc161de5774e12f2389 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Tue, 30 Apr 2019 00:45:29 +0300 Subject: [PATCH] #1: Add test case for panic when trying to store response without textures --- .../queue/in_memory_textures_storage.go | 19 +++---------------- .../queue/in_memory_textures_storage_test.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/api/mojang/queue/in_memory_textures_storage.go b/api/mojang/queue/in_memory_textures_storage.go index 4019caa..0abc05b 100644 --- a/api/mojang/queue/in_memory_textures_storage.go +++ b/api/mojang/queue/in_memory_textures_storage.go @@ -1,7 +1,6 @@ package queue import ( - "errors" "sync" "time" @@ -71,21 +70,9 @@ func (s *inMemoryTexturesStorage) StoreTextures(textures *mojang.SignedTexturesR s.lock.Lock() defer s.lock.Unlock() - var texturesProp *mojang.Property - for _, prop := range textures.Props { - if prop.Name == "textures" { - texturesProp = prop - break - } - } - - if texturesProp == nil { - panic(errors.New("unable to find textures property")) - } - - decoded, err := mojang.DecodeTextures(texturesProp.Value) - if err != nil { - panic(err) + decoded := textures.DecodeTextures() + if decoded == nil { + panic("unable to decode textures") } s.data[textures.Id] = &inMemoryItem{ diff --git a/api/mojang/queue/in_memory_textures_storage_test.go b/api/mojang/queue/in_memory_textures_storage_test.go index d774955..27bce9f 100644 --- a/api/mojang/queue/in_memory_textures_storage_test.go +++ b/api/mojang/queue/in_memory_textures_storage_test.go @@ -109,6 +109,21 @@ func TestInMemoryTexturesStorage_StoreTextures(t *testing.T) { assert.Equal(texturesWithSkin, result) assert.Nil(err) }) + + t.Run("should panic if textures prop is not decoded", func(t *testing.T) { + assert := testify.New(t) + + toStore := &mojang.SignedTexturesResponse{ + Id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + Name: "mock", + Props: []*mojang.Property{}, + } + + assert.PanicsWithValue("unable to decode textures", func() { + storage := CreateInMemoryTexturesStorage() + storage.StoreTextures(toStore) + }) + }) } func TestInMemoryTexturesStorage_GarbageCollection(t *testing.T) {