mirror of
https://github.com/status-im/status-go.git
synced 2025-01-31 00:48:01 +00:00
e6738e5343
This changes updates the logic for generating identity-images to populate the `clock` value instead of initialising with zero. This change also updates the identity-image url format functions to include the `clock` value in the returned url so clients can rely on that url for triggering refetches of identity images when they've been updated.
71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
package images
|
|
|
|
import (
|
|
"image"
|
|
"image/png"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGenerateBannerImage_NoScaleUp(t *testing.T) {
|
|
// Test image 256x256
|
|
testImage := path + "status.png"
|
|
identityImage, err := GenerateBannerImage(testImage, 50, 50, 150, 100)
|
|
|
|
require.NoError(t, err)
|
|
require.Exactly(t, identityImage.Name, BannerIdentityName)
|
|
require.Positive(t, len(identityImage.Payload))
|
|
// Ensure we don't scale it up. That will be done inefficiently in backend instead of frontend
|
|
require.Exactly(t, identityImage.Width, 100)
|
|
require.Exactly(t, identityImage.Height, 50)
|
|
require.Exactly(t, identityImage.FileSize, len(identityImage.Payload))
|
|
require.Exactly(t, identityImage.ResizeTarget, int(BannerDim))
|
|
}
|
|
|
|
func TestGenerateBannerImage_ShrinkOnly(t *testing.T) {
|
|
// Generate test image bigger than BannerDim
|
|
testImage := image.NewRGBA(image.Rect(0, 0, int(BannerDim)+10, int(BannerDim)+20))
|
|
|
|
tmpTestFilePath := t.TempDir() + "/test.png"
|
|
file, err := os.Create(tmpTestFilePath)
|
|
require.NoError(t, err)
|
|
defer file.Close()
|
|
|
|
err = png.Encode(file, testImage)
|
|
require.NoError(t, err)
|
|
|
|
identityImage, error := GenerateBannerImage(tmpTestFilePath, 0, 0, int(BannerDim)+5, int(BannerDim)+10)
|
|
|
|
require.NoError(t, error)
|
|
require.Positive(t, len(identityImage.Payload))
|
|
// Ensure we scale it down by the small side
|
|
require.Exactly(t, identityImage.Width, int(BannerDim))
|
|
require.Exactly(t, identityImage.Height, 805)
|
|
}
|
|
|
|
func TestGenerateIdentityImages(t *testing.T) {
|
|
// Create image data
|
|
testImage := image.NewRGBA(image.Rect(0, 0, int(BannerDim)+10, int(BannerDim)+20))
|
|
|
|
// Create a temporary file for storing the image data
|
|
tmpTestFilePath := t.TempDir() + "/test.png"
|
|
file, err := os.Create(tmpTestFilePath)
|
|
require.NoError(t, err)
|
|
defer file.Close()
|
|
|
|
// Save the image data to the temporary file
|
|
err = png.Encode(file, testImage)
|
|
require.NoError(t, err)
|
|
|
|
// Generate the identity images
|
|
identityImages, err := GenerateIdentityImages(tmpTestFilePath, 100, 100, 500, 500)
|
|
require.NoError(t, err)
|
|
|
|
// Check the identity images have a valid clock value
|
|
for _, image := range identityImages {
|
|
require.NotEqual(t, image.Clock, uint64(0))
|
|
}
|
|
}
|