Files
team/server/channels/jobs/export_delete_test.go
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

103 lines
2.6 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package jobs_test
import (
"os"
"path/filepath"
"testing"
"time"
"github.com/hanzoteam/server/server/public/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestExportDelete(t *testing.T) {
mainHelper.Parallel(t)
// Create a temporary export directory
fileSettingsDir, err := os.MkdirTemp("", "")
require.NoError(t, err)
relExportDir := "./export"
exportDir := filepath.Join(fileSettingsDir, relExportDir)
t.Cleanup(func() {
err = os.RemoveAll(fileSettingsDir)
assert.NoError(t, err)
})
retentionDays := 1
updateConfig := func(cfg *model.Config) {
*cfg.FileSettings.DriverName = model.ImageDriverLocal
*cfg.FileSettings.Directory = fileSettingsDir
*cfg.ExportSettings.Directory = relExportDir
*cfg.ExportSettings.RetentionDays = retentionDays
}
th := SetupWithUpdateCfg(t, updateConfig)
// Create test files with different timestamps
files := []string{
"old_export.zip",
"recent_export.zip",
"normal.txt",
"test_export.zip",
"data.json",
}
// Create directories that should not be deleted
dirs := []string{
"data",
"data/subfolder",
}
for _, dir := range dirs {
err = os.MkdirAll(filepath.Join(exportDir, dir), 0755)
require.NoError(t, err)
// Add a file in each directory that should not be deleted
err = os.WriteFile(filepath.Join(exportDir, dir, "file.txt"), []byte("test"), 0644)
require.NoError(t, err)
}
for _, file := range files {
err = os.WriteFile(filepath.Join(exportDir, file), []byte("test"), 0644)
require.NoError(t, err)
}
// Set old timestamps for files that should be deleted
oldTime := time.Now().Add(-(time.Duration(retentionDays) * 24 * time.Hour) - 1*time.Hour)
err = os.Chtimes(filepath.Join(exportDir, "old_export.zip"), oldTime, oldTime)
require.NoError(t, err)
err = os.Chtimes(filepath.Join(exportDir, "test_export.zip"), oldTime, oldTime)
require.NoError(t, err)
// Start the workers
th.SetupWorkers(t)
// Run the export delete job
th.RunJob(t, model.JobTypeExportDelete, nil)
// Verify files that should still exist
for _, name := range []string{
"recent_export.zip",
"normal.txt",
"data.json",
"data/file.txt",
"data/subfolder/file.txt",
} {
_, err := os.Stat(filepath.Join(exportDir, name))
require.NoError(t, err, "Expected file/directory to exist: %s", name)
}
// Verify files that should be deleted
for _, name := range []string{
"old_export.zip",
"test_export.zip",
} {
_, err := os.Stat(filepath.Join(exportDir, name))
require.True(t, os.IsNotExist(err), "Expected file to be deleted: %s", name)
}
}