MM-16479: panic on io.Copy error in test (#11684)

* MM-16479: panic on io.Copy error in test

I'm unable to reproduce the original report on MM-16479, but in a bid to help track down a potential failure in the future, I've added a panic on err returned from `io.Copy` within the plugin, as this seems like the only path on which the hook could return successfully but fail to show the updated contents.

* assert number of copied bytes

* log n on io.Copy error too
This commit is contained in:
Jesse Hallam
2019-07-31 14:27:46 -03:00
committed by GitHub
parent 53cae67ede
commit de88adfc0b

View File

@@ -246,7 +246,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
post.Message = "prefix_" + post.Message
return post, ""
}
@@ -610,8 +610,8 @@ func TestHookFileWillBeUploaded(t *testing.T) {
import (
"io"
"bytes"
"fmt"
"bytes"
"github.com/mattermost/mattermost-server/plugin"
"github.com/mattermost/mattermost-server/model"
)
@@ -624,13 +624,16 @@ func TestHookFileWillBeUploaded(t *testing.T) {
var buf bytes.Buffer
n, err := buf.ReadFrom(file)
if err != nil {
return info, fmt.Sprintf("FAILED to read input file n: %v, err: %v", n, err)
panic(fmt.Sprintf("buf.ReadFrom failed, reading %d bytes: %s", err.Error()))
}
outbuf := bytes.NewBufferString("changedtext")
n, err = io.Copy(output, outbuf)
if int(n) != len("changedtext") || err != nil {
return info, fmt.Sprintf("FAILED to write output file n: %v, err: %v", n, err)
if err != nil {
panic(fmt.Sprintf("io.Copy failed after %d bytes: %s", n, err.Error()))
}
if n != 11 {
panic(fmt.Sprintf("io.Copy only copied %d bytes", n))
}
info.Name = "modifiedinfo"
return info, ""