From de88adfc0bc6f23d834349a28cb1ce696602c50b Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Wed, 31 Jul 2019 14:27:46 -0300 Subject: [PATCH] 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 --- app/plugin_hooks_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/plugin_hooks_test.go b/app/plugin_hooks_test.go index 694fe7fec7..a20a12a0bf 100644 --- a/app/plugin_hooks_test.go +++ b/app/plugin_hooks_test.go @@ -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, ""