filer_multipart_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package s3api
  2. import (
  3. "github.com/aws/aws-sdk-go/aws"
  4. "github.com/aws/aws-sdk-go/service/s3"
  5. "github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
  6. "github.com/stretchr/testify/assert"
  7. "testing"
  8. "time"
  9. )
  10. func TestInitiateMultipartUploadResult(t *testing.T) {
  11. expected := `<?xml version="1.0" encoding="UTF-8"?>
  12. <InitiateMultipartUploadResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Bucket>example-bucket</Bucket><Key>example-object</Key><UploadId>VXBsb2FkIElEIGZvciA2aWWpbmcncyBteS1tb3ZpZS5tMnRzIHVwbG9hZA</UploadId></InitiateMultipartUploadResult>`
  13. response := &InitiateMultipartUploadResult{
  14. CreateMultipartUploadOutput: s3.CreateMultipartUploadOutput{
  15. Bucket: aws.String("example-bucket"),
  16. Key: aws.String("example-object"),
  17. UploadId: aws.String("VXBsb2FkIElEIGZvciA2aWWpbmcncyBteS1tb3ZpZS5tMnRzIHVwbG9hZA"),
  18. },
  19. }
  20. encoded := string(s3err.EncodeXMLResponse(response))
  21. if encoded != expected {
  22. t.Errorf("unexpected output: %s\nexpecting:%s", encoded, expected)
  23. }
  24. }
  25. func TestListPartsResult(t *testing.T) {
  26. expected := `<?xml version="1.0" encoding="UTF-8"?>
  27. <ListPartsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Part><ETag>&#34;12345678&#34;</ETag><LastModified>1970-01-01T00:00:00Z</LastModified><PartNumber>1</PartNumber><Size>123</Size></Part></ListPartsResult>`
  28. response := &ListPartsResult{
  29. Part: []*s3.Part{
  30. {
  31. PartNumber: aws.Int64(int64(1)),
  32. LastModified: aws.Time(time.Unix(0, 0).UTC()),
  33. Size: aws.Int64(int64(123)),
  34. ETag: aws.String("\"12345678\""),
  35. },
  36. },
  37. }
  38. encoded := string(s3err.EncodeXMLResponse(response))
  39. if encoded != expected {
  40. t.Errorf("unexpected output: %s\nexpecting:%s", encoded, expected)
  41. }
  42. }
  43. func Test_parsePartNumber(t *testing.T) {
  44. tests := []struct {
  45. name string
  46. fileName string
  47. partNum int
  48. }{
  49. {
  50. "first",
  51. "0001_uuid.part",
  52. 1,
  53. },
  54. {
  55. "second",
  56. "0002.part",
  57. 2,
  58. },
  59. }
  60. for _, tt := range tests {
  61. t.Run(tt.name, func(t *testing.T) {
  62. partNumber, _ := parsePartNumber(tt.fileName)
  63. assert.Equalf(t, tt.partNum, partNumber, "parsePartNumber(%v)", tt.fileName)
  64. })
  65. }
  66. }