2019-02-27 15:23:04 +08:00
|
|
|
package s3api
|
|
|
|
|
|
|
|
import (
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
2019-02-27 15:23:04 +08:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestListBucketsHandler(t *testing.T) {
|
|
|
|
|
|
|
|
expected := `<?xml version="1.0" encoding="UTF-8"?>
|
2024-07-05 02:00:41 +08:00
|
|
|
<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>`
|
2019-02-27 15:23:04 +08:00
|
|
|
var response ListAllMyBucketsResult
|
|
|
|
|
2024-07-05 02:00:41 +08:00
|
|
|
var bucketsList ListAllMyBucketsList
|
|
|
|
bucketsList.Bucket = append(bucketsList.Bucket, ListAllMyBucketsEntry{
|
|
|
|
Name: "test1",
|
|
|
|
CreationDate: time.Date(2011, 4, 9, 12, 34, 49, 0, time.UTC),
|
2019-02-27 15:23:04 +08:00
|
|
|
})
|
2024-07-05 02:00:41 +08:00
|
|
|
bucketsList.Bucket = append(bucketsList.Bucket, ListAllMyBucketsEntry{
|
|
|
|
Name: "test2",
|
|
|
|
CreationDate: time.Date(2011, 2, 9, 12, 34, 49, 0, time.UTC),
|
2019-02-27 15:23:04 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
response = ListAllMyBucketsResult{
|
2024-07-05 02:00:41 +08:00
|
|
|
Owner: CanonicalUser{
|
|
|
|
ID: "",
|
|
|
|
DisplayName: "",
|
2019-02-27 15:23:04 +08:00
|
|
|
},
|
2024-07-05 02:00:41 +08:00
|
|
|
Buckets: bucketsList,
|
2019-02-27 15:23:04 +08:00
|
|
|
}
|
|
|
|
|
2021-06-11 12:50:21 +08:00
|
|
|
encoded := string(s3err.EncodeXMLResponse(response))
|
2019-02-27 15:23:04 +08:00
|
|
|
if encoded != expected {
|
2024-07-05 02:00:41 +08:00
|
|
|
t.Errorf("unexpected output:%s\nexpecting:%s", encoded, expected)
|
2019-02-27 15:23:04 +08:00
|
|
|
}
|
|
|
|
}
|