-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
:white_check_makr: ♻️ Add test for s3/writer and Refactor. (#672)
* feat: wrapper for s3 manager Signed-off-by: hlts2 <[email protected]> * fix: refactor Signed-off-by: hlts2 <[email protected]> * fix: s3 type Signed-off-by: hlts2 <[email protected]> * fix typo Signed-off-by: hlts2 <[email protected]> * fix: apply suggestion Signed-off-by: hlts2 <[email protected]> * add test for writer Signed-off-by: hlts2 <[email protected]> * delete unncessary file Signed-off-by: hlts2 <[email protected]> * delete unncessary code Signed-off-by: hlts2 <[email protected]> * fix: apply feedback Signed-off-by: hlts2 <[email protected]> * fix: add comment Signed-off-by: hlts2 <[email protected]> * fix: fatal error Signed-off-by: hlts2 <[email protected]> * fix: fatal error Signed-off-by: hlts2 <[email protected]> * fix: fatal error Signed-off-by: hlts2 <[email protected]> * fix: fatal error Signed-off-by: hlts2 <[email protected]> * fix: apply suggestion Signed-off-by: hlts2 <[email protected]> * fix: apply suggestion Signed-off-by: hlts2 <[email protected]> * 🤖 Update license headers / Format go codes and yaml files Signed-off-by: vdaas-ci <[email protected]> Co-authored-by: vdaas-ci <[email protected]>
- Loading branch information
Showing
13 changed files
with
437 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt ) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
package s3 | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
) | ||
|
||
// S3 is type alias for s3.S3. | ||
type S3 = s3.S3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt ) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
package s3iface | ||
|
||
import "github.com/aws/aws-sdk-go/service/s3/s3iface" | ||
|
||
// S3API is type alias for s3iface.S3API. | ||
type S3API = s3iface.S3API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt ) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
package s3manager | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/s3/s3manager" | ||
"github.com/vdaas/vald/internal/db/storage/blob/s3/sdk/s3/s3iface" | ||
) | ||
|
||
type ( | ||
// Uploader is type alias of s3manager.Uploader. | ||
Uploader = s3manager.Uploader | ||
// UploadInput is type alias of s3manager.UploadInput. | ||
UploadInput = s3manager.UploadInput | ||
// UploadOutput is type alias of s3manager.UploadOutput. | ||
UploadOutput = s3manager.UploadOutput | ||
) | ||
|
||
// UploadClient represents an interface to upload to s3. | ||
type UploadClient interface { | ||
UploadWithContext(ctx aws.Context, input *UploadInput, opts ...func(*Uploader)) (*UploadOutput, error) | ||
} | ||
|
||
// S3Manager represents an interface to create object of s3manager package. | ||
type S3Manager interface { | ||
NewUploaderWithClient(svc s3iface.S3API, options ...func(*Uploader)) UploadClient | ||
} | ||
|
||
type s3mngr struct{} | ||
|
||
// New returns S3Manager implementation. | ||
func New() S3Manager { | ||
return new(s3mngr) | ||
} | ||
|
||
// NewUploaderWithClient returns UploadClient implementation. | ||
func (*s3mngr) NewUploaderWithClient(svc s3iface.S3API, options ...func(*Uploader)) UploadClient { | ||
return s3manager.NewUploaderWithClient(svc, options...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt ) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
package writer | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/vdaas/vald/internal/db/storage/blob/s3/sdk/s3/s3iface" | ||
"github.com/vdaas/vald/internal/db/storage/blob/s3/sdk/s3/s3manager" | ||
) | ||
|
||
// S3Manager represents mock of s3manager.S3Manager. | ||
type MockS3Manager struct { | ||
NewUploaderWithClientFunc func(s3iface.S3API, ...func(*s3manager.Uploader)) s3manager.UploadClient | ||
} | ||
|
||
// NewUploaderWithClient calls NewUNewUploaderWithClientFunc. | ||
func (m *MockS3Manager) NewUploaderWithClient(svc s3iface.S3API, opts ...func(*s3manager.Uploader)) s3manager.UploadClient { | ||
return m.NewUploaderWithClientFunc(svc, opts...) | ||
} | ||
|
||
type MockUploadClient struct { | ||
UploadWithContextFunc func(aws.Context, *s3manager.UploadInput, ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error) | ||
} | ||
|
||
func (m *MockUploadClient) UploadWithContext(ctx aws.Context, input *s3manager.UploadInput, opts ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error) { | ||
return m.UploadWithContextFunc(ctx, input, opts...) | ||
} | ||
|
||
// MockWriteCloser represents mock of io.WriteCloser. | ||
type MockWriteCloser struct { | ||
WriteFunc func(p []byte) (n int, err error) | ||
CloseFunc func() error | ||
} | ||
|
||
func (m *MockWriteCloser) Write(p []byte) (n int, err error) { | ||
return m.WriteFunc(p) | ||
} | ||
|
||
func (m *MockWriteCloser) Close() error { | ||
return m.CloseFunc() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.