Skip to content

Commit

Permalink
fix: ensure that identity images are generated with a current-time cl…
Browse files Browse the repository at this point in the history
…ock value instead of zero by default
  • Loading branch information
seanstrom committed Jan 7, 2025
1 parent f7d73be commit b67ad51
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions images/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package images
import (
"bytes"
"image"
"time"
)

func GenerateImageVariants(cImg image.Image) ([]IdentityImage, error) {
Expand All @@ -25,6 +26,7 @@ func GenerateImageVariants(cImg image.Image) ([]IdentityImage, error) {
Height: rImg.Bounds().Dy(),
FileSize: bb.Len(),
ResizeTarget: int(s),
Clock: uint64(time.Now().UnixMilli()),
}

iis = append(iis, ii)
Expand Down
24 changes: 24 additions & 0 deletions images/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,27 @@ func TestGenerateBannerImage_ShrinkOnly(t *testing.T) {
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))
}
}

0 comments on commit b67ad51

Please sign in to comment.