mattermost/server/public/model/group_test.go
Jesse Hallam e3fbf8711f
MM-68149: Upgrade to Go 1.26.2 (#36418)
* MM-68149: upgrade to Go 1.26.2

Update go directive in go.mod and .go-version.

* MM-68149: replace pointer helpers with Go 1.26 new()

Go 1.26 extends the built-in new() to accept an initial value expression,
making typed-pointer helpers like model.NewPointer(x), bToP(x), and boolPtr(x)
redundant. Replace every call site with new(x) and remove the now-unused
helper functions and their //go:fix inline directives.

* MM-68149: apply go fix for reflect API and format-string changes

- reflect.Ptr → reflect.Pointer (renamed in Go 1.18, deprecated alias removed in 1.26)
- reflect range-over-struct: for i := 0; i < t.NumField(); i++ → for field := range t.Fields()
  and the equivalent for Methods() and interface types
- Fix format-string concatenation and variadic-arg mismatches flagged by go vet

* MM-68149: update JPEG fixtures and test infrastructure for Go 1.26 encoder

Go 1.26 ships a new image/jpeg encoder that produces slightly different output.
Regenerate all JPEG fixture files and switch the comparison helpers from
byte-equality to pixel-level comparison with a small per-channel tolerance,
so minor encoder drift across patch versions is handled automatically.

Add -update-fixtures flag to make it easy to regenerate fixtures after future
major Go upgrades. Document the update procedure in tests/README.md.

* MM-68149: CI check that go fix ./... produces no changes

* Fix real bugs flagged by CodeRabbit review

- group.go: set newGroup.MemberCount not group.MemberCount (member count
  was populated on the wrong variable and lost before publish/return)
- file_test.go: guard compareImage(GetFilePreview) on the preview slice
  length, not the thumbnail slice length (copy-paste error)
- config_test.go: remove duplicate MinimumLength assignment

* fixup! Fix real bugs flagged by CodeRabbit review
2026-05-12 15:59:12 +00:00

99 lines
2.2 KiB
Go

package model
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGroupAuditable(t *testing.T) {
t.Run("zero value", func(t *testing.T) {
var g Group
m := g.Auditable()
require.NotNil(t, m)
assert.Equal(t, "", m["remote_id"])
})
t.Run("values set", func(t *testing.T) {
id := NewId()
now := GetMillis()
g := Group{
Id: id,
Name: new("some name"),
DisplayName: "some display name",
Source: GroupSourceLdap,
RemoteId: new("some_remote"),
CreateAt: now,
UpdateAt: now,
DeleteAt: now,
HasSyncables: true,
MemberCount: new(10),
AllowReference: true,
}
m := g.Auditable()
expected := map[string]any{
"id": id,
"source": GroupSourceLdap,
"remote_id": "some_remote",
"create_at": now,
"update_at": now,
"delete_at": now,
"has_syncables": true,
"member_count": 10,
"allow_reference": true,
}
assert.Equal(t, expected, m)
})
}
func TestGroupLogClone(t *testing.T) {
t.Run("zero value", func(t *testing.T) {
var g Group
l := g.LogClone()
require.NotNil(t, l)
m, ok := l.(map[string]any)
require.True(t, ok)
assert.Equal(t, "", m["remote_id"])
})
t.Run("values set", func(t *testing.T) {
id := NewId()
now := GetMillis()
g := Group{
Id: id,
Name: new("some name"),
DisplayName: "some display name",
Source: GroupSourceLdap,
RemoteId: new("some_remote"),
CreateAt: now,
UpdateAt: now,
DeleteAt: now,
HasSyncables: true,
MemberCount: new(10),
AllowReference: true,
}
l := g.LogClone()
m, ok := l.(map[string]any)
require.True(t, ok)
expected := map[string]any{
"id": id,
"name": "some name",
"display_name": "some display name",
"source": GroupSourceLdap,
"remote_id": "some_remote",
"create_at": now,
"update_at": now,
"delete_at": now,
"has_syncables": true,
"member_count": 10,
"allow_reference": true,
}
assert.Equal(t, expected, m)
})
}