|
| 1 | +/* |
| 2 | +* Copyright 2021 Layotto Authors |
| 3 | +* |
| 4 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +* you may not use this file except in compliance with the License. |
| 6 | +* You may obtain a copy of the License at |
| 7 | +* |
| 8 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +* |
| 10 | +* Unless required by applicable law or agreed to in writing, software |
| 11 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +* See the License for the specific language governing permissions and |
| 14 | +* limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package oss |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "mosn.io/layotto/components/pkg/info" |
| 24 | +) |
| 25 | + |
| 26 | +type mockOss struct{} |
| 27 | + |
| 28 | +func (m *mockOss) Init(ctx context.Context, cfg *Config) error { |
| 29 | + return nil |
| 30 | +} |
| 31 | + |
| 32 | +func (m *mockOss) GetObject(ctx context.Context, input *GetObjectInput) (*GetObjectOutput, error) { |
| 33 | + return nil, nil |
| 34 | +} |
| 35 | + |
| 36 | +func (m *mockOss) PutObject(ctx context.Context, input *PutObjectInput) (*PutObjectOutput, error) { |
| 37 | + return nil, nil |
| 38 | +} |
| 39 | + |
| 40 | +func (m *mockOss) DeleteObject(ctx context.Context, input *DeleteObjectInput) (*DeleteObjectOutput, error) { |
| 41 | + return nil, nil |
| 42 | +} |
| 43 | + |
| 44 | +func (m *mockOss) PutObjectTagging(ctx context.Context, input *PutObjectTaggingInput) (*PutObjectTaggingOutput, error) { |
| 45 | + return nil, nil |
| 46 | +} |
| 47 | + |
| 48 | +func (m *mockOss) DeleteObjectTagging(ctx context.Context, input *DeleteObjectTaggingInput) (*DeleteObjectTaggingOutput, error) { |
| 49 | + return nil, nil |
| 50 | +} |
| 51 | + |
| 52 | +func (m *mockOss) GetObjectTagging(ctx context.Context, input *GetObjectTaggingInput) (*GetObjectTaggingOutput, error) { |
| 53 | + return nil, nil |
| 54 | +} |
| 55 | + |
| 56 | +func (m *mockOss) CopyObject(ctx context.Context, input *CopyObjectInput) (*CopyObjectOutput, error) { |
| 57 | + return nil, nil |
| 58 | +} |
| 59 | + |
| 60 | +func (m *mockOss) DeleteObjects(ctx context.Context, input *DeleteObjectsInput) (*DeleteObjectsOutput, error) { |
| 61 | + return nil, nil |
| 62 | +} |
| 63 | + |
| 64 | +func (m *mockOss) ListObjects(ctx context.Context, input *ListObjectsInput) (*ListObjectsOutput, error) { |
| 65 | + return nil, nil |
| 66 | +} |
| 67 | + |
| 68 | +func (m *mockOss) GetObjectCannedAcl(ctx context.Context, input *GetObjectCannedAclInput) (*GetObjectCannedAclOutput, error) { |
| 69 | + return nil, nil |
| 70 | +} |
| 71 | + |
| 72 | +func (m *mockOss) PutObjectCannedAcl(ctx context.Context, input *PutObjectCannedAclInput) (*PutObjectCannedAclOutput, error) { |
| 73 | + return nil, nil |
| 74 | +} |
| 75 | + |
| 76 | +func (m *mockOss) RestoreObject(ctx context.Context, input *RestoreObjectInput) (*RestoreObjectOutput, error) { |
| 77 | + return nil, nil |
| 78 | +} |
| 79 | + |
| 80 | +func (m *mockOss) CreateMultipartUpload(ctx context.Context, input *CreateMultipartUploadInput) (*CreateMultipartUploadOutput, error) { |
| 81 | + return nil, nil |
| 82 | +} |
| 83 | + |
| 84 | +func (m *mockOss) UploadPart(ctx context.Context, input *UploadPartInput) (*UploadPartOutput, error) { |
| 85 | + return nil, nil |
| 86 | +} |
| 87 | + |
| 88 | +func (m *mockOss) UploadPartCopy(ctx context.Context, input *UploadPartCopyInput) (*UploadPartCopyOutput, error) { |
| 89 | + return nil, nil |
| 90 | +} |
| 91 | + |
| 92 | +func (m *mockOss) CompleteMultipartUpload(ctx context.Context, input *CompleteMultipartUploadInput) (*CompleteMultipartUploadOutput, error) { |
| 93 | + return nil, nil |
| 94 | +} |
| 95 | + |
| 96 | +func (m *mockOss) AbortMultipartUpload(ctx context.Context, input *AbortMultipartUploadInput) (*AbortMultipartUploadOutput, error) { |
| 97 | + return nil, nil |
| 98 | +} |
| 99 | + |
| 100 | +func (m *mockOss) ListMultipartUploads(ctx context.Context, input *ListMultipartUploadsInput) (*ListMultipartUploadsOutput, error) { |
| 101 | + return nil, nil |
| 102 | +} |
| 103 | + |
| 104 | +func TestRegistry(t *testing.T) { |
| 105 | + r := NewRegistry(info.NewRuntimeInfo()) |
| 106 | + |
| 107 | + // Register a factory |
| 108 | + f := NewFactory("mock", func() Oss { |
| 109 | + return &mockOss{} |
| 110 | + }) |
| 111 | + r.Register(f) |
| 112 | + |
| 113 | + // Test that the factory was registered |
| 114 | + if _, ok := r.(*registry).oss[f.CompType]; !ok { |
| 115 | + t.Errorf("Factory with component type %q was not registered", f.CompType) |
| 116 | + } |
| 117 | + |
| 118 | + // Test that a registered component can be created |
| 119 | + oss, err := r.Create(f.CompType) |
| 120 | + if err != nil { |
| 121 | + t.Errorf("Unexpected error creating component: %v", err) |
| 122 | + } |
| 123 | + if _, ok := oss.(*mockOss); !ok { |
| 124 | + t.Errorf("Expected component type *mockOss, but got %T", oss) |
| 125 | + } |
| 126 | + |
| 127 | + // Test that creating an unregistered component returns an error |
| 128 | + _, err = r.Create("unregistered") |
| 129 | + if err == nil { |
| 130 | + t.Error("Expected an error creating unregistered component, but got nil") |
| 131 | + } |
| 132 | + expectedErrMsg := "service component unregistered is not registered" |
| 133 | + if err.Error() != expectedErrMsg { |
| 134 | + t.Errorf("Expected error message %q, but got %q", expectedErrMsg, err.Error()) |
| 135 | + } |
| 136 | +} |
| 137 | + |
| 138 | +func (m *mockOss) ListObjectVersions(ctx context.Context, input *ListObjectVersionsInput) (*ListObjectVersionsOutput, error) { |
| 139 | + //TODO implement me |
| 140 | + panic("implement me") |
| 141 | +} |
| 142 | + |
| 143 | +func (m *mockOss) HeadObject(ctx context.Context, input *HeadObjectInput) (*HeadObjectOutput, error) { |
| 144 | + //TODO implement me |
| 145 | + panic("implement me") |
| 146 | +} |
| 147 | + |
| 148 | +func (m *mockOss) IsObjectExist(ctx context.Context, input *IsObjectExistInput) (*IsObjectExistOutput, error) { |
| 149 | + //TODO implement me |
| 150 | + panic("implement me") |
| 151 | +} |
| 152 | + |
| 153 | +func (m *mockOss) SignURL(ctx context.Context, input *SignURLInput) (*SignURLOutput, error) { |
| 154 | + //TODO implement me |
| 155 | + panic("implement me") |
| 156 | +} |
| 157 | + |
| 158 | +func (m *mockOss) UpdateDownloadBandwidthRateLimit(ctx context.Context, input *UpdateBandwidthRateLimitInput) error { |
| 159 | + //TODO implement me |
| 160 | + panic("implement me") |
| 161 | +} |
| 162 | + |
| 163 | +func (m *mockOss) UpdateUploadBandwidthRateLimit(ctx context.Context, input *UpdateBandwidthRateLimitInput) error { |
| 164 | + //TODO implement me |
| 165 | + panic("implement me") |
| 166 | +} |
| 167 | + |
| 168 | +func (m *mockOss) AppendObject(ctx context.Context, input *AppendObjectInput) (*AppendObjectOutput, error) { |
| 169 | + //TODO implement me |
| 170 | + panic("implement me") |
| 171 | +} |
| 172 | + |
| 173 | +func (m *mockOss) ListParts(ctx context.Context, input *ListPartsInput) (*ListPartsOutput, error) { |
| 174 | + //TODO implement me |
| 175 | + panic("implement me") |
| 176 | +} |
0 commit comments