s3api_objects_list_handlers_test.go 1.3 KB

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