1package s3crypto_test
2
3import (
4	"io/ioutil"
5	"strings"
6	"testing"
7
8	"github.com/aws/aws-sdk-go/service/s3/s3crypto"
9)
10
11func TestCryptoReadCloserRead(t *testing.T) {
12	expectedStr := "HELLO WORLD "
13	str := strings.NewReader(expectedStr)
14	rc := &s3crypto.CryptoReadCloser{Body: ioutil.NopCloser(str), Decrypter: str}
15
16	b, err := ioutil.ReadAll(rc)
17	if err != nil {
18		t.Errorf("expected no error, but received %v", err)
19	}
20	if expectedStr != string(b) {
21		t.Errorf("expected %s, but received %s", expectedStr, string(b))
22	}
23}
24
25func TestCryptoReadCloserClose(t *testing.T) {
26	data := "HELLO WORLD "
27	expectedStr := ""
28
29	str := strings.NewReader(data)
30	rc := &s3crypto.CryptoReadCloser{Body: ioutil.NopCloser(str), Decrypter: str}
31	rc.Close()
32
33	b, err := ioutil.ReadAll(rc)
34	if err != nil {
35		t.Errorf("expected no error, but received %v", err)
36	}
37	if expectedStr != string(b) {
38		t.Errorf("expected %s, but received %s", expectedStr, string(b))
39	}
40}
41