2017-05-11 14:39:54 +00:00
|
|
|
package awstesting_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/awstesting"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestReadCloserClose(t *testing.T) {
|
|
|
|
rc := awstesting.ReadCloser{Size: 1}
|
|
|
|
err := rc.Close()
|
|
|
|
|
2017-09-30 14:27:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("expect nil, got %v", err)
|
|
|
|
}
|
|
|
|
if !rc.Closed {
|
|
|
|
t.Errorf("expect closed, was not")
|
|
|
|
}
|
|
|
|
if e, a := rc.Size, 1; e != a {
|
|
|
|
t.Errorf("expect %v, got %v", e, a)
|
|
|
|
}
|
2017-05-11 14:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadCloserRead(t *testing.T) {
|
|
|
|
rc := awstesting.ReadCloser{Size: 5}
|
|
|
|
b := make([]byte, 2)
|
|
|
|
|
|
|
|
n, err := rc.Read(b)
|
|
|
|
|
2017-09-30 14:27:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("expect nil, got %v", err)
|
|
|
|
}
|
|
|
|
if e, a := n, 2; e != a {
|
|
|
|
t.Errorf("expect %v, got %v", e, a)
|
|
|
|
}
|
|
|
|
if rc.Closed {
|
|
|
|
t.Errorf("expect not to be closed")
|
|
|
|
}
|
|
|
|
if e, a := rc.Size, 3; e != a {
|
|
|
|
t.Errorf("expect %v, got %v", e, a)
|
|
|
|
}
|
2017-05-11 14:39:54 +00:00
|
|
|
|
|
|
|
err = rc.Close()
|
2017-09-30 14:27:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("expect nil, got %v", err)
|
|
|
|
}
|
2017-05-11 14:39:54 +00:00
|
|
|
n, err = rc.Read(b)
|
2017-09-30 14:27:27 +00:00
|
|
|
if e, a := err, io.EOF; e != a {
|
|
|
|
t.Errorf("expect %v, got %v", e, a)
|
|
|
|
}
|
|
|
|
if e, a := n, 0; e != a {
|
|
|
|
t.Errorf("expect %v, got %v", e, a)
|
|
|
|
}
|
2017-05-11 14:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadCloserReadAll(t *testing.T) {
|
|
|
|
rc := awstesting.ReadCloser{Size: 5}
|
|
|
|
b := make([]byte, 5)
|
|
|
|
|
|
|
|
n, err := rc.Read(b)
|
|
|
|
|
2017-09-30 14:27:27 +00:00
|
|
|
if e, a := err, io.EOF; e != a {
|
|
|
|
t.Errorf("expect %v, got %v", e, a)
|
|
|
|
}
|
|
|
|
if e, a := n, 5; e != a {
|
|
|
|
t.Errorf("expect %v, got %v", e, a)
|
|
|
|
}
|
|
|
|
if rc.Closed {
|
|
|
|
t.Errorf("expect not to be closed")
|
|
|
|
}
|
|
|
|
if e, a := rc.Size, 0; e != a {
|
|
|
|
t.Errorf("expect %v, got %v", e, a)
|
|
|
|
}
|
2017-05-11 14:39:54 +00:00
|
|
|
}
|