Skip to content

Commit

Permalink
[MM-57379] Still generate support_packet.yaml even if an error occurs (
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Apr 5, 2024
1 parent 5f6ef75 commit 1a9355b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/channels/app/support_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func (a *App) GenerateSupportPacket(c request.CTX) []model.FileData {
if err != nil {
c.Logger().Error("Failed to generate file for support package", mlog.Err(err), mlog.String("file", name))
warnings = append(warnings, err.Error())
} else if fileData != nil {
}

if fileData != nil {
fileDatas = append(fileDatas, *fileData)
}
}
Expand Down
37 changes: 37 additions & 0 deletions server/channels/app/support_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/v8/channels/app/platform"
smocks "github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks"
"github.com/mattermost/mattermost/server/v8/config"
fmocks "github.com/mattermost/mattermost/server/v8/platform/shared/filestore/mocks"
)
Expand Down Expand Up @@ -154,6 +155,42 @@ func TestGenerateSupportPacket(t *testing.T) {
rFileNames = append(rFileNames, fileData.Filename)
}
assert.ElementsMatch(t, testFiles, rFileNames)

t.Run("steps that generated an error should still return file data", func(t *testing.T) {
mockStore := smocks.Store{}

// Mock the post store to trigger an error
ps := &smocks.PostStore{}
ps.On("AnalyticsPostCount", &model.PostCountOptions{}).Return(int64(0), errors.New("all broken"))
ps.On("ClearCaches")
mockStore.On("Post").Return(ps)

mockStore.On("User").Return(th.App.Srv().Store().User())
mockStore.On("Channel").Return(th.App.Srv().Store().Channel())
mockStore.On("Post").Return(th.App.Srv().Store().Post())
mockStore.On("Team").Return(th.App.Srv().Store().Team())
mockStore.On("Job").Return(th.App.Srv().Store().Job())
mockStore.On("FileInfo").Return(th.App.Srv().Store().FileInfo())
mockStore.On("Webhook").Return(th.App.Srv().Store().Webhook())
mockStore.On("System").Return(th.App.Srv().Store().System())
mockStore.On("License").Return(th.App.Srv().Store().License())
mockStore.On("Close").Return(nil)
mockStore.On("GetDBSchemaVersion").Return(1, nil)
mockStore.On("GetDbVersion", false).Return("1.0.0", nil)
th.App.Srv().SetStore(&mockStore)

fileDatas := th.App.GenerateSupportPacket(th.Context)

var rFileNames []string
for _, fileData := range fileDatas {
require.NotNil(t, fileData)
assert.Positive(t, len(fileData.Body))

rFileNames = append(rFileNames, fileData.Filename)
}
assert.Contains(t, rFileNames, "warning.txt")
assert.Contains(t, rFileNames, "support_packet.yaml")
})
}

func TestGetNotificationsLog(t *testing.T) {
Expand Down

0 comments on commit 1a9355b

Please sign in to comment.