You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

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