-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobject_test.go
72 lines (61 loc) · 1.65 KB
/
object_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package example03object
import (
"s3-demo/core/s3action"
"s3-demo/log"
"testing"
"github.com/stretchr/testify/suite"
)
type ObjectSuite struct {
suite.Suite
S3Action *s3action.S3Base
BucketName string
Region string
FileName string
ObjectKey string
}
func TestObjectSuite(t *testing.T) {
suite.Run(t, new(ObjectSuite))
}
func (s *ObjectSuite) SetupSuite() {
s.S3Action = s3action.NewS3Client()
s.BucketName = "yuki-testobject-2022-12"
s.Region = "us-west-2"
s.FileName = "test.csv"
s.ObjectKey = "yuki-test-object-csv"
// s.NoError(s.S3Action.CreateBucket(s.BucketName, s.Region))
}
func (s *ObjectSuite) TearDownSuite() {
// s.NoError(s.S3Action.DeleteBucket(s.BucketName))
}
func (s *ObjectSuite) Test01Upload() {
err := s.S3Action.UploadFile(s.BucketName, s.ObjectKey, s.FileName)
s.NoError(err)
}
func (s *ObjectSuite) Test02GetObjectList() {
objects, err := s.S3Action.GetObjectList(s.BucketName)
s.NoError(err)
for _, obj := range objects {
log.Infof("object: %v", *obj.Key)
log.Infof("object: %v", *obj.ETag)
}
}
func (s *ObjectSuite) Test03GetObject() {
s2, err := s.S3Action.GetObjectContent(s.BucketName, s.ObjectKey)
s.NoError(err)
log.Infof("get obj: %v", s2)
}
func (s *ObjectSuite) Test04GetObjectUrl() {
s2, err := s.S3Action.GetObjectUrl(s.BucketName, s.ObjectKey)
s.NoError(err)
log.Infof("get obj: %v", s2)
}
func (s *ObjectSuite) Test04DeleteObjectListByKeys() {
objects, err := s.S3Action.GetObjectList(s.BucketName)
keyList := make([]string, len(objects))
for i, obj := range objects {
keyList[i] = *obj.Key
}
s.NoError(err)
err = s.S3Action.DeleteObjectListByKeys(s.BucketName, keyList)
s.NoError(err)
}