| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package s3_test |
| 5 |
|
| 6 |
import ( |
| 7 |
"bytes" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/aws/aws-sdk-go/aws" |
| 11 |
"github.com/aws/aws-sdk-go/awstesting/unit" |
| 12 |
"github.com/aws/aws-sdk-go/service/s3" |
| 13 |
) |
| 14 |
|
| 15 |
func TestAdd100Continue_Added(t *testing.T) { |
| 16 |
svc := s3.New(unit.Session) |
| 17 |
r, _ := svc.PutObjectRequest(&s3.PutObjectInput{ |
| 18 |
Bucket: aws.String("bucket"), |
| 19 |
Key: aws.String("dest"), |
| 20 |
Body: bytes.NewReader(make([]byte, 1024*1024*5)), |
| 21 |
}) |
| 22 |
|
| 23 |
err := r.Sign() |
| 24 |
|
| 25 |
if err != nil { |
| 26 |
t.Errorf("expected no error, but received %v", err) |
| 27 |
} |
| 28 |
if e, a := "100-continue", r.HTTPRequest.Header.Get("Expect"); e != a { |
| 29 |
t.Errorf("expected %s, but received %s", e, a) |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
func TestAdd100Continue_SkipDisabled(t *testing.T) { |
| 34 |
svc := s3.New(unit.Session, aws.NewConfig().WithS3Disable100Continue(true)) |
| 35 |
r, _ := svc.PutObjectRequest(&s3.PutObjectInput{ |
| 36 |
Bucket: aws.String("bucket"), |
| 37 |
Key: aws.String("dest"), |
| 38 |
Body: bytes.NewReader(make([]byte, 1024*1024*5)), |
| 39 |
}) |
| 40 |
|
| 41 |
err := r.Sign() |
| 42 |
|
| 43 |
if err != nil { |
| 44 |
t.Errorf("expected no error, but received %v", err) |
| 45 |
} |
| 46 |
if r.HTTPRequest.Header.Get("Expect") != "" { |
| 47 |
t.Errorf("expected empty value, but received %s", r.HTTPRequest.Header.Get("Expect")) |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
func TestAdd100Continue_SkipNonPUT(t *testing.T) { |
| 52 |
svc := s3.New(unit.Session) |
| 53 |
r, _ := svc.GetObjectRequest(&s3.GetObjectInput{ |
| 54 |
Bucket: aws.String("bucket"), |
| 55 |
Key: aws.String("dest"), |
| 56 |
}) |
| 57 |
|
| 58 |
err := r.Sign() |
| 59 |
|
| 60 |
if err != nil { |
| 61 |
t.Errorf("expected no error, but received %v", err) |
| 62 |
} |
| 63 |
if r.HTTPRequest.Header.Get("Expect") != "" { |
| 64 |
t.Errorf("expected empty value, but received %s", r.HTTPRequest.Header.Get("Expect")) |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
func TestAdd100Continue_SkipTooSmall(t *testing.T) { |
| 69 |
svc := s3.New(unit.Session) |
| 70 |
r, _ := svc.PutObjectRequest(&s3.PutObjectInput{ |
| 71 |
Bucket: aws.String("bucket"), |
| 72 |
Key: aws.String("dest"), |
| 73 |
Body: bytes.NewReader(make([]byte, 1024*1024*1)), |
| 74 |
}) |
| 75 |
|
| 76 |
err := r.Sign() |
| 77 |
|
| 78 |
if err != nil { |
| 79 |
t.Errorf("expected no error, but received %v", err) |
| 80 |
} |
| 81 |
if r.HTTPRequest.Header.Get("Expect") != "" { |
| 82 |
t.Errorf("expected empty value, but received %s", r.HTTPRequest.Header.Get("Expect")) |
| 83 |
} |
| 84 |
} |