s3api_bucket_handlers_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package s3api
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
  4. "testing"
  5. "time"
  6. )
  7. func TestListBucketsHandler(t *testing.T) {
  8. expected := `<?xml version="1.0" encoding="UTF-8"?>
  9. <ListAllMyBucketsResult><Owner><ID></ID></Owner><Buckets><Bucket><Name>test1</Name><CreationDate>2011-04-09T12:34:49Z</CreationDate></Bucket><Bucket><Name>test2</Name><CreationDate>2011-02-09T12:34:49Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult>`
  10. var response ListAllMyBucketsResult
  11. var bucketsList ListAllMyBucketsList
  12. bucketsList.Bucket = append(bucketsList.Bucket, ListAllMyBucketsEntry{
  13. Name: "test1",
  14. CreationDate: time.Date(2011, 4, 9, 12, 34, 49, 0, time.UTC),
  15. })
  16. bucketsList.Bucket = append(bucketsList.Bucket, ListAllMyBucketsEntry{
  17. Name: "test2",
  18. CreationDate: time.Date(2011, 2, 9, 12, 34, 49, 0, time.UTC),
  19. })
  20. response = ListAllMyBucketsResult{
  21. Owner: CanonicalUser{
  22. ID: "",
  23. DisplayName: "",
  24. },
  25. Buckets: bucketsList,
  26. }
  27. encoded := string(s3err.EncodeXMLResponse(response))
  28. if encoded != expected {
  29. t.Errorf("unexpected output:%s\nexpecting:%s", encoded, expected)
  30. }
  31. }