From 8d37f0438b821c619b7059738a6b80bedf505e00 Mon Sep 17 00:00:00 2001 From: yellow chicks Date: Wed, 13 Jul 2022 00:36:52 +0800 Subject: [PATCH] optimize: add context to huawei/obs (#1820) * optimize: add context to huawei/obs Signed-off-by: 1046102779 * optimize: add context to huawei/obs Signed-off-by: 1046102779 * optimize: add context to huawei/obs Signed-off-by: 1046102779 Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com> Signed-off-by: Andrew Duss --- bindings/huawei/obs/obs.go | 30 ++++---- bindings/huawei/obs/obs_service.go | 36 +++++----- bindings/huawei/obs/obs_test.go | 112 ++++++++++++++--------------- 3 files changed, 91 insertions(+), 87 deletions(-) diff --git a/bindings/huawei/obs/obs.go b/bindings/huawei/obs/obs.go index 4a8d380298..6d0fd912a7 100644 --- a/bindings/huawei/obs/obs.go +++ b/bindings/huawei/obs/obs.go @@ -130,7 +130,7 @@ func (o *HuaweiOBS) Operations() []bindings.OperationKind { } } -func (o *HuaweiOBS) create(req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { +func (o *HuaweiOBS) create(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { d, err := strconv.Unquote(string(req.Data)) if err == nil { req.Data = []byte(d) @@ -151,7 +151,7 @@ func (o *HuaweiOBS) create(req *bindings.InvokeRequest) (*bindings.InvokeRespons input.Bucket = o.metadata.Bucket input.Body = r - out, err := o.service.PutObject(input) + out, err := o.service.PutObject(ctx, input) if err != nil { return nil, fmt.Errorf("obs binding error. putobject: %w", err) } @@ -169,7 +169,7 @@ func (o *HuaweiOBS) create(req *bindings.InvokeRequest) (*bindings.InvokeRespons }, nil } -func (o *HuaweiOBS) upload(req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { +func (o *HuaweiOBS) upload(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { var payload uploadPayload err := json.Unmarshal(req.Data, &payload) if err != nil { @@ -189,7 +189,7 @@ func (o *HuaweiOBS) upload(req *bindings.InvokeRequest) (*bindings.InvokeRespons input.Bucket = o.metadata.Bucket input.SourceFile = payload.SourceFile - out, err := o.service.PutFile(input) + out, err := o.service.PutFile(ctx, input) if err != nil { return nil, fmt.Errorf("obs binding error. putfile: %w", err) } @@ -207,7 +207,7 @@ func (o *HuaweiOBS) upload(req *bindings.InvokeRequest) (*bindings.InvokeRespons }, nil } -func (o *HuaweiOBS) get(req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { +func (o *HuaweiOBS) get(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { var key string if val, ok := req.Metadata[metadataKey]; ok && val != "" { key = val @@ -219,7 +219,7 @@ func (o *HuaweiOBS) get(req *bindings.InvokeRequest) (*bindings.InvokeResponse, input.Bucket = o.metadata.Bucket input.Key = key - out, err := o.service.GetObject(input) + out, err := o.service.GetObject(ctx, input) if err != nil { return nil, fmt.Errorf("obs binding error. error getting obs object: %w", err) } @@ -243,7 +243,7 @@ func (o *HuaweiOBS) get(req *bindings.InvokeRequest) (*bindings.InvokeResponse, }, nil } -func (o *HuaweiOBS) delete(req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { +func (o *HuaweiOBS) delete(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { var key string if val, ok := req.Metadata[metadataKey]; ok && val != "" { key = val @@ -255,7 +255,7 @@ func (o *HuaweiOBS) delete(req *bindings.InvokeRequest) (*bindings.InvokeRespons input.Bucket = o.metadata.Bucket input.Key = key - out, err := o.service.DeleteObject(input) + out, err := o.service.DeleteObject(ctx, input) if err != nil { return nil, fmt.Errorf("obs binding error. error deleting obs object: %w", err) } @@ -273,7 +273,7 @@ func (o *HuaweiOBS) delete(req *bindings.InvokeRequest) (*bindings.InvokeRespons }, nil } -func (o *HuaweiOBS) list(req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { +func (o *HuaweiOBS) list(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { var payload listPayload err := json.Unmarshal(req.Data, &payload) if err != nil { @@ -292,7 +292,7 @@ func (o *HuaweiOBS) list(req *bindings.InvokeRequest) (*bindings.InvokeResponse, input.Prefix = payload.Prefix input.Delimiter = payload.Delimiter - out, err := o.service.ListObjects(input) + out, err := o.service.ListObjects(ctx, input) if err != nil { return nil, fmt.Errorf("obs binding error. error listing obs objects: %w", err) } @@ -310,15 +310,15 @@ func (o *HuaweiOBS) list(req *bindings.InvokeRequest) (*bindings.InvokeResponse, func (o *HuaweiOBS) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { switch req.Operation { case bindings.CreateOperation: - return o.create(req) + return o.create(ctx, req) case UploadOperation: - return o.upload(req) + return o.upload(ctx, req) case bindings.GetOperation: - return o.get(req) + return o.get(ctx, req) case bindings.DeleteOperation: - return o.delete(req) + return o.delete(ctx, req) case bindings.ListOperation: - return o.list(req) + return o.list(ctx, req) default: return nil, fmt.Errorf("obs binding error. unsupported operation %s", req.Operation) } diff --git a/bindings/huawei/obs/obs_service.go b/bindings/huawei/obs/obs_service.go index b7a458f34c..b70e66b4da 100644 --- a/bindings/huawei/obs/obs_service.go +++ b/bindings/huawei/obs/obs_service.go @@ -13,16 +13,20 @@ limitations under the License. package obs -import "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" +import ( + "context" + + "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" +) // HuaweiOBSAPI holds only the necessary API functions from the OBS SDK // The interface can also provide a way to implement stubs for the purpose of unit testing. type HuaweiOBSAPI interface { - PutObject(input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) - PutFile(input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) - GetObject(input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) - DeleteObject(input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) - ListObjects(input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) + PutObject(ctx context.Context, input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) + PutFile(ctx context.Context, input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) + GetObject(ctx context.Context, input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) + DeleteObject(ctx context.Context, input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) + ListObjects(ctx context.Context, input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) } // HuaweiOBSService is a service layer which wraps the actual OBS SDK client to provide the API functions @@ -31,22 +35,22 @@ type HuaweiOBSService struct { client *obs.ObsClient } -func (s *HuaweiOBSService) PutObject(input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { - return s.client.PutObject(input) +func (s *HuaweiOBSService) PutObject(ctx context.Context, input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { + return s.client.PutObject(input, obs.WithRequestContext(ctx)) } -func (s *HuaweiOBSService) PutFile(input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) { - return s.client.PutFile(input) +func (s *HuaweiOBSService) PutFile(ctx context.Context, input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) { + return s.client.PutFile(input, obs.WithRequestContext(ctx)) } -func (s *HuaweiOBSService) GetObject(input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { - return s.client.GetObject(input) +func (s *HuaweiOBSService) GetObject(ctx context.Context, input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { + return s.client.GetObject(input, obs.WithRequestContext(ctx)) } -func (s *HuaweiOBSService) DeleteObject(input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) { - return s.client.DeleteObject(input) +func (s *HuaweiOBSService) DeleteObject(ctx context.Context, input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) { + return s.client.DeleteObject(input, obs.WithRequestContext(ctx)) } -func (s *HuaweiOBSService) ListObjects(input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { - return s.client.ListObjects(input) +func (s *HuaweiOBSService) ListObjects(ctx context.Context, input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { + return s.client.ListObjects(input, obs.WithRequestContext(ctx)) } diff --git a/bindings/huawei/obs/obs_test.go b/bindings/huawei/obs/obs_test.go index 8f8195fcab..f26197275a 100644 --- a/bindings/huawei/obs/obs_test.go +++ b/bindings/huawei/obs/obs_test.go @@ -33,31 +33,31 @@ import ( // MockHuaweiOBSService is a mock service layer which mimics the OBS API functions // and it implements the HuaweiOBSAPI through stubs. type MockHuaweiOBSService struct { - PutObjectFn func(input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) - PutFileFn func(input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) - GetObjectFn func(input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) - DeleteObjectFn func(input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) - ListObjectsFn func(input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) + PutObjectFn func(ctx context.Context, input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) + PutFileFn func(ctx context.Context, input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) + GetObjectFn func(ctx context.Context, input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) + DeleteObjectFn func(ctx context.Context, input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) + ListObjectsFn func(ctx context.Context, input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) } -func (m *MockHuaweiOBSService) PutObject(input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { - return m.PutObjectFn(input) +func (m *MockHuaweiOBSService) PutObject(ctx context.Context, input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { + return m.PutObjectFn(ctx, input) } -func (m *MockHuaweiOBSService) PutFile(input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) { - return m.PutFileFn(input) +func (m *MockHuaweiOBSService) PutFile(ctx context.Context, input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) { + return m.PutFileFn(ctx, input) } -func (m *MockHuaweiOBSService) GetObject(input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { - return m.GetObjectFn(input) +func (m *MockHuaweiOBSService) GetObject(ctx context.Context, input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { + return m.GetObjectFn(ctx, input) } -func (m *MockHuaweiOBSService) DeleteObject(input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) { - return m.DeleteObjectFn(input) +func (m *MockHuaweiOBSService) DeleteObject(ctx context.Context, input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) { + return m.DeleteObjectFn(ctx, input) } -func (m *MockHuaweiOBSService) ListObjects(input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { - return m.ListObjectsFn(input) +func (m *MockHuaweiOBSService) ListObjects(ctx context.Context, input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { + return m.ListObjectsFn(ctx, input) } func TestParseMetadata(t *testing.T) { @@ -154,7 +154,7 @@ func TestCreateOperation(t *testing.T) { t.Run("Successfully create object with key", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - PutObjectFn: func(input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { + PutObjectFn: func(ctx context.Context, input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { return &obs.PutObjectOutput{ BaseModel: obs.BaseModel{ StatusCode: 200, @@ -176,7 +176,7 @@ func TestCreateOperation(t *testing.T) { Data: []byte(`"Hello OBS"`), } - out, err := mo.create(req) + out, err := mo.create(context.Background(), req) assert.Nil(t, err) var data createResponse @@ -188,7 +188,7 @@ func TestCreateOperation(t *testing.T) { t.Run("Successfully create object with uuid", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - PutObjectFn: func(input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { + PutObjectFn: func(ctx context.Context, input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { return &obs.PutObjectOutput{ BaseModel: obs.BaseModel{ StatusCode: 200, @@ -207,7 +207,7 @@ func TestCreateOperation(t *testing.T) { Data: []byte(`"Hello OBS"`), } - out, err := mo.create(req) + out, err := mo.create(context.Background(), req) assert.Nil(t, err) var data createResponse @@ -219,7 +219,7 @@ func TestCreateOperation(t *testing.T) { t.Run("Successfully create null object with no data", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - PutObjectFn: func(input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { + PutObjectFn: func(ctx context.Context, input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { return &obs.PutObjectOutput{ BaseModel: obs.BaseModel{ StatusCode: 200, @@ -240,14 +240,14 @@ func TestCreateOperation(t *testing.T) { }, } - _, err := mo.create(req) + _, err := mo.create(context.Background(), req) assert.Nil(t, err) }) t.Run("Fail create object with obs internal error", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - PutObjectFn: func(input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { + PutObjectFn: func(ctx context.Context, input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { return nil, fmt.Errorf("error while creating object") }, }, @@ -265,7 +265,7 @@ func TestCreateOperation(t *testing.T) { Data: []byte(`"Hello OBS"`), } - _, err := mo.create(req) + _, err := mo.create(context.Background(), req) assert.NotNil(t, err) }) } @@ -274,7 +274,7 @@ func TestUploadOperation(t *testing.T) { t.Run("Successfully upload object with key", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - PutFileFn: func(input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) { + PutFileFn: func(ctx context.Context, input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) { return &obs.PutObjectOutput{ BaseModel: obs.BaseModel{ StatusCode: 200, @@ -296,7 +296,7 @@ func TestUploadOperation(t *testing.T) { Data: []byte(`{"sourceFile": "dummy-path"}`), } - out, err := mo.upload(req) + out, err := mo.upload(context.Background(), req) assert.Nil(t, err) var data createResponse @@ -308,7 +308,7 @@ func TestUploadOperation(t *testing.T) { t.Run("Successfully upload object with uuid", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - PutFileFn: func(input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) { + PutFileFn: func(ctx context.Context, input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) { return &obs.PutObjectOutput{ BaseModel: obs.BaseModel{ StatusCode: 200, @@ -327,7 +327,7 @@ func TestUploadOperation(t *testing.T) { Data: []byte(`{"sourceFile": "dummy-path"}`), } - out, err := mo.upload(req) + out, err := mo.upload(context.Background(), req) assert.Nil(t, err) var data createResponse @@ -339,7 +339,7 @@ func TestUploadOperation(t *testing.T) { t.Run("Fail upload object with obs internal error", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - PutFileFn: func(input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) { + PutFileFn: func(ctx context.Context, input *obs.PutFileInput) (output *obs.PutObjectOutput, err error) { return nil, fmt.Errorf("error while creating object") }, }, @@ -357,7 +357,7 @@ func TestUploadOperation(t *testing.T) { Data: []byte(`{"sourceFile": "dummy-path"}`), } - _, err := mo.upload(req) + _, err := mo.upload(context.Background(), req) assert.NotNil(t, err) }) } @@ -366,7 +366,7 @@ func TestGetOperation(t *testing.T) { t.Run("Successfully get object", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - GetObjectFn: func(input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { + GetObjectFn: func(ctx context.Context, input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { return &obs.GetObjectOutput{ GetObjectMetadataOutput: obs.GetObjectMetadataOutput{ BaseModel: obs.BaseModel{ @@ -391,7 +391,7 @@ func TestGetOperation(t *testing.T) { }, } - _, err := mo.get(req) + _, err := mo.get(context.Background(), req) assert.Nil(t, err) }) @@ -408,14 +408,14 @@ func TestGetOperation(t *testing.T) { Operation: "get", } - _, err := mo.get(req) + _, err := mo.get(context.Background(), req) assert.NotNil(t, err) }) t.Run("Fail get object with obs internal error", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - GetObjectFn: func(input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { + GetObjectFn: func(ctx context.Context, input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { return nil, fmt.Errorf("error while getting object") }, }, @@ -432,14 +432,14 @@ func TestGetOperation(t *testing.T) { }, } - _, err := mo.get(req) + _, err := mo.get(context.Background(), req) assert.NotNil(t, err) }) t.Run("Fail get object with no response data", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - GetObjectFn: func(input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { + GetObjectFn: func(ctx context.Context, input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { return &obs.GetObjectOutput{ GetObjectMetadataOutput: obs.GetObjectMetadataOutput{ BaseModel: obs.BaseModel{ @@ -464,7 +464,7 @@ func TestGetOperation(t *testing.T) { }, } - _, err := mo.get(req) + _, err := mo.get(context.Background(), req) assert.NotNil(t, err) }) } @@ -473,7 +473,7 @@ func TestDeleteOperation(t *testing.T) { t.Run("Successfully delete object", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - DeleteObjectFn: func(input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) { + DeleteObjectFn: func(ctx context.Context, input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) { return &obs.DeleteObjectOutput{ BaseModel: obs.BaseModel{ StatusCode: 200, @@ -494,7 +494,7 @@ func TestDeleteOperation(t *testing.T) { }, } - out, err := mo.delete(req) + out, err := mo.delete(context.Background(), req) assert.Nil(t, err) var data createResponse @@ -516,14 +516,14 @@ func TestDeleteOperation(t *testing.T) { Operation: "delete", } - _, err := mo.delete(req) + _, err := mo.delete(context.Background(), req) assert.NotNil(t, err) }) t.Run("Fail delete object with obs internal error", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - DeleteObjectFn: func(input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) { + DeleteObjectFn: func(ctx context.Context, input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) { return nil, fmt.Errorf("error while deleting object") }, }, @@ -540,7 +540,7 @@ func TestDeleteOperation(t *testing.T) { }, } - _, err := mo.delete(req) + _, err := mo.delete(context.Background(), req) assert.NotNil(t, err) }) } @@ -549,7 +549,7 @@ func TestListOperation(t *testing.T) { t.Run("Successfully list objects", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - ListObjectsFn: func(input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { + ListObjectsFn: func(ctx context.Context, input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { return &obs.ListObjectsOutput{ BaseModel: obs.BaseModel{ StatusCode: 200, @@ -571,14 +571,14 @@ func TestListOperation(t *testing.T) { Data: []byte("{\"maxResults\": 10}"), } - _, err := mo.list(req) + _, err := mo.list(context.Background(), req) assert.Nil(t, err) }) t.Run("Fail list objects with obs internal error", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - ListObjectsFn: func(input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { + ListObjectsFn: func(ctx context.Context, input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { return nil, fmt.Errorf("error while listing objects") }, }, @@ -596,14 +596,14 @@ func TestListOperation(t *testing.T) { Data: []byte("{\"maxResults\": 10}"), } - _, err := mo.list(req) + _, err := mo.list(context.Background(), req) assert.NotNil(t, err) }) t.Run("Successfully list objects with default maxResults", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - ListObjectsFn: func(input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { + ListObjectsFn: func(ctx context.Context, input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { return &obs.ListObjectsOutput{ BaseModel: obs.BaseModel{ StatusCode: 200, @@ -625,7 +625,7 @@ func TestListOperation(t *testing.T) { Data: []byte("{\"key\": \"value\"}"), } - _, err := mo.list(req) + _, err := mo.list(context.Background(), req) assert.Nil(t, err) }) } @@ -634,7 +634,7 @@ func TestInvoke(t *testing.T) { t.Run("Successfully invoke create", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - PutObjectFn: func(input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { + PutObjectFn: func(ctx context.Context, input *obs.PutObjectInput) (output *obs.PutObjectOutput, err error) { return &obs.PutObjectOutput{ BaseModel: obs.BaseModel{ StatusCode: 200, @@ -652,14 +652,14 @@ func TestInvoke(t *testing.T) { Operation: "create", } - _, err := mo.Invoke(context.TODO(), req) + _, err := mo.Invoke(context.Background(), req) assert.Nil(t, err) }) t.Run("Successfully invoke get", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - GetObjectFn: func(input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { + GetObjectFn: func(ctx context.Context, input *obs.GetObjectInput) (output *obs.GetObjectOutput, err error) { return &obs.GetObjectOutput{ GetObjectMetadataOutput: obs.GetObjectMetadataOutput{ BaseModel: obs.BaseModel{ @@ -684,14 +684,14 @@ func TestInvoke(t *testing.T) { }, } - _, err := mo.Invoke(context.TODO(), req) + _, err := mo.Invoke(context.Background(), req) assert.Nil(t, err) }) t.Run("Successfully invoke delete", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - DeleteObjectFn: func(input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) { + DeleteObjectFn: func(ctx context.Context, input *obs.DeleteObjectInput) (output *obs.DeleteObjectOutput, err error) { return &obs.DeleteObjectOutput{ BaseModel: obs.BaseModel{ StatusCode: 204, @@ -712,14 +712,14 @@ func TestInvoke(t *testing.T) { }, } - _, err := mo.Invoke(context.TODO(), req) + _, err := mo.Invoke(context.Background(), req) assert.Nil(t, err) }) t.Run("Successfully invoke list", func(t *testing.T) { mo := &HuaweiOBS{ service: &MockHuaweiOBSService{ - ListObjectsFn: func(input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { + ListObjectsFn: func(ctx context.Context, input *obs.ListObjectsInput) (output *obs.ListObjectsOutput, err error) { return &obs.ListObjectsOutput{ BaseModel: obs.BaseModel{ StatusCode: 200, @@ -741,7 +741,7 @@ func TestInvoke(t *testing.T) { Data: []byte("{\"maxResults\": 10}"), } - _, err := mo.Invoke(context.TODO(), req) + _, err := mo.Invoke(context.Background(), req) assert.Nil(t, err) }) @@ -758,7 +758,7 @@ func TestInvoke(t *testing.T) { Operation: "unknown", } - _, err := mo.Invoke(context.TODO(), req) + _, err := mo.Invoke(context.Background(), req) assert.NotNil(t, err) }) }