s3api_objects_list_handlers_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package s3api
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/s3api/s3err"
  4. "testing"
  5. "time"
  6. )
  7. func TestListObjectsHandler(t *testing.T) {
  8. // https://docs.aws.amazon.com/AmazonS3/latest/API/v2-RESTBucketGET.html
  9. expected := `<?xml version="1.0" encoding="UTF-8"?>
  10. <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>test_container</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>1.zip</Key><ETag>&#34;4397da7a7649e8085de9916c240e8166&#34;</ETag><Size>1234567</Size><Owner><ID>65a011niqo39cdf8ec533ec3d1ccaafsa932</ID></Owner><StorageClass>STANDARD</StorageClass><LastModified>2011-04-09T12:34:49Z</LastModified></Contents></ListBucketResult>`
  11. response := ListBucketResult{
  12. Name: "test_container",
  13. Prefix: "",
  14. Marker: "",
  15. NextMarker: "",
  16. MaxKeys: 1000,
  17. IsTruncated: false,
  18. Contents: []ListEntry{{
  19. Key: "1.zip",
  20. LastModified: time.Date(2011, 4, 9, 12, 34, 49, 0, time.UTC),
  21. ETag: "\"4397da7a7649e8085de9916c240e8166\"",
  22. Size: 1234567,
  23. Owner: CanonicalUser{
  24. ID: "65a011niqo39cdf8ec533ec3d1ccaafsa932",
  25. },
  26. StorageClass: "STANDARD",
  27. }},
  28. }
  29. encoded := string(s3err.EncodeXMLResponse(response))
  30. if encoded != expected {
  31. t.Errorf("unexpected output: %s\nexpecting:%s", encoded, expected)
  32. }
  33. }