mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
* 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
115 lines
2.8 KiB
Go
115 lines
2.8 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package commands
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/hashicorp/go-multierror"
|
|
|
|
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
|
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func (s *MmctlUnitTestSuite) TestIntegrityCmd() {
|
|
s.Run("Integrity check succeeds", func() {
|
|
printer.Clean()
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Bool("confirm", true, "")
|
|
|
|
mockData := model.RelationalIntegrityCheckData{
|
|
ParentName: "parent",
|
|
ChildName: "child",
|
|
ParentIdAttr: "parentIdAttr",
|
|
ChildIdAttr: "childIdAttr",
|
|
Records: []model.OrphanedRecord{
|
|
{
|
|
ParentId: new("parentId"),
|
|
ChildId: new("childId"),
|
|
},
|
|
},
|
|
}
|
|
mockResults := []model.IntegrityCheckResult{
|
|
{
|
|
Data: mockData,
|
|
Err: nil,
|
|
},
|
|
}
|
|
s.client.
|
|
EXPECT().
|
|
CheckIntegrity(context.TODO()).
|
|
Return(mockResults, &model.Response{}, nil).
|
|
Times(1)
|
|
|
|
err := integrityCmdF(s.client, cmd, []string{})
|
|
s.Require().Nil(err)
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().Equal(mockData, printer.GetLines()[0])
|
|
})
|
|
|
|
s.Run("Integrity check fails", func() {
|
|
printer.Clean()
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Bool("confirm", true, "")
|
|
|
|
s.client.
|
|
EXPECT().
|
|
CheckIntegrity(context.TODO()).
|
|
Return(nil, &model.Response{}, errors.New("mock error")).
|
|
Times(1)
|
|
|
|
err := integrityCmdF(s.client, cmd, []string{})
|
|
s.Require().NotNil(err)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().Equal("unable to perform integrity check. Error: mock error", err.Error())
|
|
})
|
|
|
|
s.Run("Integrity check with errors", func() {
|
|
printer.Clean()
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Bool("confirm", true, "")
|
|
|
|
mockData := model.RelationalIntegrityCheckData{
|
|
ParentName: "parent",
|
|
ChildName: "child",
|
|
ParentIdAttr: "parentIdAttr",
|
|
ChildIdAttr: "childIdAttr",
|
|
Records: []model.OrphanedRecord{
|
|
{
|
|
ParentId: new("parentId"),
|
|
ChildId: new("childId"),
|
|
},
|
|
},
|
|
}
|
|
mockResults := []model.IntegrityCheckResult{
|
|
{
|
|
Data: nil,
|
|
Err: errors.New("test error"),
|
|
},
|
|
{
|
|
Data: mockData,
|
|
Err: nil,
|
|
},
|
|
}
|
|
s.client.
|
|
EXPECT().
|
|
CheckIntegrity(context.TODO()).
|
|
Return(mockResults, &model.Response{}, nil).
|
|
Times(1)
|
|
var expected error
|
|
expected = multierror.Append(expected, errors.New("test error"))
|
|
|
|
err := integrityCmdF(s.client, cmd, []string{})
|
|
s.Require().EqualError(err, expected.Error())
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Len(printer.GetErrorLines(), 1)
|
|
s.Require().Equal(mockData, printer.GetLines()[0])
|
|
s.Require().Equal("test error", printer.GetErrorLines()[0])
|
|
})
|
|
}
|