s3api_bucket_handlers_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package s3api
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/aws/aws-sdk-go/aws"
  6. "github.com/aws/aws-sdk-go/service/s3"
  7. )
  8. func TestListBucketsHandler(t *testing.T) {
  9. expected := `<?xml version="1.0" encoding="UTF-8"?>
  10. <ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Owner><DisplayName></DisplayName><ID></ID></Owner><Buckets><Bucket><CreationDate>2011-04-09T12:34:49Z</CreationDate><Name>test1</Name></Bucket><Bucket><CreationDate>2011-02-09T12:34:49Z</CreationDate><Name>test2</Name></Bucket></Buckets></ListAllMyBucketsResult>`
  11. var response ListAllMyBucketsResult
  12. var buckets []*s3.Bucket
  13. buckets = append(buckets, &s3.Bucket{
  14. Name: aws.String("test1"),
  15. CreationDate: aws.Time(time.Date(2011, 4, 9, 12, 34, 49, 0, time.UTC)),
  16. })
  17. buckets = append(buckets, &s3.Bucket{
  18. Name: aws.String("test2"),
  19. CreationDate: aws.Time(time.Date(2011, 2, 9, 12, 34, 49, 0, time.UTC)),
  20. })
  21. response = ListAllMyBucketsResult{
  22. Owner: &s3.Owner{
  23. ID: aws.String(""),
  24. DisplayName: aws.String(""),
  25. },
  26. Buckets: buckets,
  27. }
  28. encoded := string(encodeResponse(response))
  29. if encoded != expected {
  30. t.Errorf("unexpected output: %s\nexpecting:%s", encoded, expected)
  31. }
  32. }