mattermost/server/platform/services/telemetry/telemetry_test.go
Jesse Hallam 8cace74692
MM-64486: Remove telemetry (#33606)
* MM-64486: Remove telemetry

Remove telemetry from Mattermost. We're no longer relying on Rudder upstream, and no longer making use of this information.

* recover mock for SystemStore.Get

* Fix TestClearPushNotificationSync by adding missing SystemStore mock

The test was failing because the SystemStore mock was missing the Get()
method that's required by the ServerId() function. Added the missing mock
to return a StringMap with SystemServerId.

* fix mocking issue

* Remove now-unused telemetry and constants

* Remove "Disable telemetry events" debug setting

* Remove empty functions

* Remove most "Telemetry tracking removed" comments

* Remove remains of DataPrefetch telemetry

* Remove now-unused prop from InviteMembersButton

* Remove trackDotMenuEvent

* Remove some more leftover comments

* Remove lingering logic related to trackingLocation

* Remove now-unused argument from useCopyText

* Remove lingering telemetry references from PreparingWorkspace

* fixup Remove trackDotMenuEvent

* Remove lingering telemetry references from signup page and password check

* Update snapshots and fix test broken by my changes

* Fix unintended behavior change in thread list filtering

Remove handleSetFilter wrapper that was accidentally modified during
telemetry removal. The function was calling clear() when switching to
unread filter, which was not the original behavior. Use setFilter
directly instead, restoring the original functionality.

* Remove unused useOpenDowngradeModal hook

The useOpenDowngradeModal hook was not being used anywhere in the codebase.

* Remove unused expandableLink from useExpandOverageUsersCheck

The expandableLink return value was not being used by any components.

* Re-add missing TeamLinkClicked performance telemetry

The mark(Mark.TeamLinkClicked) call was accidentally removed from the
handleSwitch function. This telemetry is needed for Looker-based
performance tracking.

* drop LogSettings.VerboseDiagnostics

---------

Co-authored-by: Harrison Healey <harrisonmhealey@gmail.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
2025-09-04 18:46:18 +00:00

97 lines
2.7 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package telemetry
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
storeMocks "github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks"
"github.com/mattermost/mattermost/server/v8/platform/services/telemetry/mocks"
)
func TestEnsureServerID(t *testing.T) {
t.Run("test ID in database and does not run twice", func(t *testing.T) {
storeMock := &storeMocks.Store{}
systemStore := storeMocks.SystemStore{}
returnValue := &model.System{
Name: model.SystemServerId,
Value: "test",
}
systemStore.On("InsertIfExists", mock.AnythingOfType("*model.System")).Return(returnValue, nil).Once()
storeMock.On("System").Return(&systemStore)
serverIfaceMock := &mocks.ServerIface{}
testLogger, _ := mlog.NewLogger()
telemetryService, err := New(serverIfaceMock, storeMock, testLogger)
require.NoError(t, err)
assert.Equal(t, "test", telemetryService.ServerID)
telemetryService.ensureServerID()
assert.Equal(t, "test", telemetryService.ServerID)
// No more calls to the store if we try to ensure it again
telemetryService.ensureServerID()
assert.Equal(t, "test", telemetryService.ServerID)
})
t.Run("new test ID created", func(t *testing.T) {
storeMock := &storeMocks.Store{}
systemStore := storeMocks.SystemStore{}
returnValue := &model.System{
Name: model.SystemServerId,
}
var generatedID string
systemStore.On("InsertIfExists", mock.AnythingOfType("*model.System")).Return(returnValue, nil).Once().Run(func(args mock.Arguments) {
s := args.Get(0).(*model.System)
returnValue.Value = s.Value
generatedID = s.Value
})
storeMock.On("System").Return(&systemStore)
serverIfaceMock := &mocks.ServerIface{}
testLogger, _ := mlog.NewLogger()
telemetryService, err := New(serverIfaceMock, storeMock, testLogger)
require.NoError(t, err)
assert.Equal(t, generatedID, telemetryService.ServerID)
})
t.Run("fail to save test ID", func(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
storeMock := &storeMocks.Store{}
systemStore := storeMocks.SystemStore{}
insertError := errors.New("insert error")
systemStore.On("InsertIfExists", mock.AnythingOfType("*model.System")).Return(nil, insertError).Times(DBAccessAttempts)
storeMock.On("System").Return(&systemStore)
serverIfaceMock := &mocks.ServerIface{}
testLogger, _ := mlog.NewLogger()
_, err := New(serverIfaceMock, storeMock, testLogger)
require.Error(t, err)
})
}