Created
September 3, 2017 11:30
-
-
Save munisystem/fc6224fbaab34fcd874a4a9e6623edd2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestS3Put(t *testing.T) { | |
cleanup, addr := prepareS3Container(t) | |
defer cleanup() | |
sess := session.Must(session.NewSession(&aws.Config{ | |
Credentials: credentials.NewStaticCredentials("dummy", "dummy", ""), | |
S3ForcePathStyle: aws.Bool(true), | |
Region: aws.String(endpoints.ApNortheast1RegionID), | |
Endpoint: aws.String(addr), | |
})) | |
svc := s3.New(sess) | |
s := &S3{Service: svc} | |
_, err := svc.CreateBucket(&s3.CreateBucketInput{ | |
Bucket: aws.String("test"), | |
CreateBucketConfiguration: &s3.CreateBucketConfiguration{ | |
LocationConstraint: aws.String("ap-northeast-1"), | |
}, | |
}) | |
if err != nil { | |
t.Fatalf("got an err: %s", err.Error()) | |
} | |
expected := "Alice in Wonderland" | |
err = s.Put("test", "alice", []byte(expected)) | |
if err != nil { | |
t.Fatalf("got an err: %s", err.Error()) | |
} | |
result, err := svc.GetObject(&s3.GetObjectInput{ | |
Bucket: aws.String("test"), | |
Key: aws.String("alice"), | |
}) | |
if err != nil { | |
t.Fatalf("got an err: %s", err.Error()) | |
} | |
b := new(bytes.Buffer) | |
io.Copy(b, result.Body) | |
actual := string(b.Bytes()) | |
if expected != actual { | |
t.Fatalf("didn't match S3 object body: expected %s, actual %s", expected, actual) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment