Skip to content

Commit

Permalink
Add extra writer test which panics on golang 1.8 unaligned writes for…
Browse files Browse the repository at this point in the history
… io.Copy to bytes.Buffer
  • Loading branch information
Jerry Jacobs committed May 30, 2017
1 parent 8bd4349 commit 9e954ed
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
Copyright (c) 2017 Jerry Jacobs <jerry.jacobs@xor-gate.org>
Copyright (c) 2013 Blake Smith <blakesmith0@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -22,6 +23,7 @@ THE SOFTWARE.
package ar

import (
"io"
"bytes"
"io/ioutil"
"os"
Expand Down Expand Up @@ -90,3 +92,35 @@ func TestWriteTooLong(t *testing.T) {
t.Errorf("Error should have been: %s", ErrWriteTooLong)
}
}

func TestIoCopyWithPadding(t *testing.T) {
hdr := new(Header)
hdr.Size = 1

var arbuf bytes.Buffer

inbuf := bytes.NewBuffer([]byte("1"))

writer := NewWriter(&arbuf)
writer.WriteHeader(hdr)
_, err := io.Copy(writer, inbuf)
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
}

func TestIoCopyWithoutPadding(t *testing.T) {
hdr := new(Header)
hdr.Size = 2

var arbuf bytes.Buffer

inbuf := bytes.NewBuffer([]byte("12"))

writer := NewWriter(&arbuf)
writer.WriteHeader(hdr)
_, err := io.Copy(writer, inbuf)
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
}

0 comments on commit 9e954ed

Please sign in to comment.