[MM-61099] Fix errcheck issues in server/channels/app/brand.go (#30679)
* [MM-28779] Fix errcheck issues in server/channels/app/brand.go Remove brand.go from the errcheck exclusion list in .golangci.yml and fixed the error by properly handling the return value from a.MoveFile(). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * [MM-28779] Add test to verify brand image backup functionality Add a new test that verifies backup of the original brand image happens when a new one is uploaded. This helps to ensure the fix for errcheck issues is working as expected. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * use seperate temporary filestore for each test * Use FileSettings.Directory instead of finding the dir programatically * Fix another test * Fix defer * Update server/channels/api4/job_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix bad bot commit * Cleanup logs message * cleanup file path * Fix error variable names * WIP:cleanup panic ussage * Revert "WIP:cleanup panic ussage" This reverts commit c3284e4427a41c818acc161926cd2535dee9a6b9. * cleanup error checks --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1cb244e876
Коммит
6de3379994
@@ -6,6 +6,7 @@ package api4
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -64,6 +65,76 @@ func TestUploadBrandImage(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestUploadBrandImageTwice(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
data, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
// First upload as system admin
|
||||
resp, err := th.SystemAdminClient.UploadBrandImage(context.Background(), data)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
// Verify the image exists and contents match what was uploaded
|
||||
receivedImg, resp, err := th.SystemAdminClient.GetBrandImage(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, receivedImg)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
require.NotEmpty(t, receivedImg, "Received image data should not be empty")
|
||||
|
||||
// Get the list of files in the brand directory
|
||||
files, err := th.App.FileBackend().ListDirectory("brand/")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, files, 1, "Expected only the original image file")
|
||||
|
||||
// ListDirectory returns paths with the directory prefix included
|
||||
fileName := files[0]
|
||||
fileName = strings.TrimPrefix(fileName, "brand/")
|
||||
require.Equal(t, "image.png", fileName, "Expected the original image file")
|
||||
|
||||
// Second upload (which should back up the previous one)
|
||||
data2, err := testutils.ReadTestFile("test.tiff")
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err = th.SystemAdminClient.UploadBrandImage(context.Background(), data2)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
// Get the list of files in the brand directory again
|
||||
files, err = th.App.FileBackend().ListDirectory("brand/")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should now have the new image.png and a backup with timestamp
|
||||
require.Len(t, files, 2, "Expected the original and backup files")
|
||||
|
||||
// Check that one of the files is image.png
|
||||
hasOriginal := false
|
||||
hasBackup := false
|
||||
for _, file := range files {
|
||||
// ListDirectory returns paths with the directory prefix included
|
||||
fileName := strings.TrimPrefix(file, "brand/")
|
||||
|
||||
if fileName == "image.png" {
|
||||
hasOriginal = true
|
||||
} else if strings.HasSuffix(fileName, ".png") && strings.Contains(fileName, "-") {
|
||||
// Backup file should have a timestamp format like 2006-01-02T15:04:05.png
|
||||
hasBackup = true
|
||||
}
|
||||
}
|
||||
|
||||
require.True(t, hasOriginal, "Original image.png file should exist")
|
||||
require.True(t, hasBackup, "Backup image file should exist")
|
||||
|
||||
// Verify the new image is available through the API and matches what was uploaded
|
||||
receivedImg2, resp, err := th.SystemAdminClient.GetBrandImage(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, receivedImg2)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
require.NotEmpty(t, receivedImg2, "Received image data should not be empty")
|
||||
}
|
||||
|
||||
func TestDeleteBrandImage(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user