mirror of
				https://github.com/elyby/chrly.git
				synced 2025-05-31 14:11:51 +05:30 
			
		
		
		
	#1: Add test case for panic when trying to store response without textures
This commit is contained in:
		@@ -1,7 +1,6 @@
 | 
				
			|||||||
package queue
 | 
					package queue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -71,21 +70,9 @@ func (s *inMemoryTexturesStorage) StoreTextures(textures *mojang.SignedTexturesR
 | 
				
			|||||||
	s.lock.Lock()
 | 
						s.lock.Lock()
 | 
				
			||||||
	defer s.lock.Unlock()
 | 
						defer s.lock.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var texturesProp *mojang.Property
 | 
						decoded := textures.DecodeTextures()
 | 
				
			||||||
	for _, prop := range textures.Props {
 | 
						if decoded == nil {
 | 
				
			||||||
		if prop.Name == "textures" {
 | 
							panic("unable to decode 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)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	s.data[textures.Id] = &inMemoryItem{
 | 
						s.data[textures.Id] = &inMemoryItem{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -109,6 +109,21 @@ func TestInMemoryTexturesStorage_StoreTextures(t *testing.T) {
 | 
				
			|||||||
		assert.Equal(texturesWithSkin, result)
 | 
							assert.Equal(texturesWithSkin, result)
 | 
				
			||||||
		assert.Nil(err)
 | 
							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) {
 | 
					func TestInMemoryTexturesStorage_GarbageCollection(t *testing.T) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user