Files
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

155 lines
3.9 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package imaging
import (
"bytes"
"flag"
"image"
"os"
"path/filepath"
"testing"
"github.com/hanzoteam/server/server/v8/channels/utils/fileutils"
"github.com/stretchr/testify/require"
)
var updateImagingFixtures = flag.Bool("update-fixtures", false, "overwrite imaging fixture files with actual output")
func TestGenerateThumbnail(t *testing.T) {
tcs := []struct {
name string
inputImg image.Image
targetWidth int
targetHeight int
expectedWidth int
expectedHeight int
}{
{
name: "empty image",
inputImg: image.NewRGBA(image.Rect(0, 0, 0, 0)),
targetWidth: 120,
targetHeight: 100,
},
{
name: "both dimensions lower than targets",
inputImg: image.NewRGBA(image.Rect(0, 0, 100, 50)),
targetWidth: 120,
targetHeight: 100,
expectedWidth: 120,
expectedHeight: 60,
},
{
name: "both dimensions equal to targets",
inputImg: image.NewRGBA(image.Rect(0, 0, 120, 100)),
targetWidth: 120,
targetHeight: 100,
expectedWidth: 120,
expectedHeight: 100,
},
{
name: "both dimensions higher than targets",
inputImg: image.NewRGBA(image.Rect(0, 0, 1000, 500)),
targetWidth: 120,
targetHeight: 100,
expectedWidth: 120,
expectedHeight: 60,
},
{
name: "width higher than target",
inputImg: image.NewRGBA(image.Rect(0, 0, 200, 100)),
targetWidth: 120,
targetHeight: 100,
expectedWidth: 120,
expectedHeight: 60,
},
{
name: "height higher than target",
inputImg: image.NewRGBA(image.Rect(0, 0, 100, 200)),
targetWidth: 120,
targetHeight: 100,
expectedWidth: 50,
expectedHeight: 100,
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
thumb := GenerateThumbnail(tc.inputImg, tc.targetWidth, tc.targetHeight)
require.Equal(t, tc.expectedWidth, thumb.Bounds().Dx(), "expectedWidth")
require.Equal(t, tc.expectedHeight, thumb.Bounds().Dy(), "expectedHeight")
})
}
}
func TestGeneratePreview(t *testing.T) {
imgDir, ok := fileutils.FindDir("tests")
require.True(t, ok)
d, err := NewDecoder(DecoderOptions{})
require.NoError(t, err)
require.NotNil(t, d)
inputFile, err := os.Open(filepath.Join(imgDir, "qa-data-graph.png"))
require.NoError(t, err)
defer inputFile.Close()
inputImg, format, err := d.Decode(inputFile)
require.NoError(t, err)
require.Equal(t, "png", format)
expectedFile, err := os.Open(filepath.Join(imgDir, "preview_test_qa_data_graph_1024.png"))
require.NoError(t, err)
defer expectedFile.Close()
expectedImg, format, err := d.Decode(expectedFile)
require.NoError(t, err)
require.Equal(t, "png", format)
preview := GeneratePreview(inputImg, 1024)
requireSameImage(t, expectedImg, preview)
}
func TestGenerateMiniPreviewImage(t *testing.T) {
imgDir, ok := fileutils.FindDir("tests")
require.True(t, ok)
d, err := NewDecoder(DecoderOptions{})
require.NoError(t, err)
require.NotNil(t, d)
inputFile, err := os.Open(filepath.Join(imgDir, "qa-data-graph.png"))
require.NoError(t, err)
defer inputFile.Close()
inputImg, format, err := d.Decode(inputFile)
require.NoError(t, err)
require.Equal(t, "png", format)
fixturePath := filepath.Join(imgDir, "mini_preview_test_qa_data_graph_16x16_q90.jpg")
out, err := GenerateMiniPreviewImage(inputImg, 16, 16, 90)
require.NoError(t, err)
if *updateImagingFixtures {
require.NoError(t, os.WriteFile(fixturePath, out, 0600))
return
}
expectedFile, err := os.Open(fixturePath)
require.NoError(t, err)
defer expectedFile.Close()
expectedImg, format, err := d.Decode(expectedFile)
require.NoError(t, err)
require.Equal(t, "jpeg", format)
actualImg, format, err := d.Decode(bytes.NewReader(out))
require.NoError(t, err)
require.Equal(t, "jpeg", format)
requireSameImage(t, expectedImg, actualImg)
}