Skip to content

Commit 6aaf438

Browse files
author
Shailza Thakur
committed
Remove dead-code
1 parent eaf359c commit 6aaf438

File tree

9 files changed

+4
-325
lines changed

9 files changed

+4
-325
lines changed

code-engine-cos2cos/bucketOperations/bucketOperations_test.go

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -17,90 +17,6 @@ func TestBucketOps(t *testing.T) {
1717
ginkgo.RunSpecs(t, "BucketOperations Suite")
1818
}
1919

20-
var _ = ginkgo.Describe("ListAvailableBuckets", func() {
21-
var (
22-
mockS3Client *MockS3Client
23-
bucket *Bucket
24-
)
25-
26-
// Before each test, initialize the mock and the Bucket struct
27-
ginkgo.BeforeEach(func() {
28-
mockS3Client = new(MockS3Client)
29-
bucket = &Bucket{
30-
Name: "test-bucket",
31-
Client: mockS3Client,
32-
}
33-
})
34-
35-
// Test case struct format
36-
type TestCase struct {
37-
name string
38-
mockResponse *s3.ListBucketsOutput
39-
mockError error
40-
expectedOutput *s3.ListBucketsOutput
41-
expectedError error
42-
}
43-
44-
// Define test cases
45-
var testCases = []TestCase{
46-
{
47-
name: "Successful ListBuckets",
48-
mockResponse: &s3.ListBucketsOutput{
49-
Buckets: []*s3.Bucket{
50-
{
51-
Name: aws.String("bucket1"),
52-
},
53-
{
54-
Name: aws.String("bucket2"),
55-
},
56-
},
57-
},
58-
mockError: nil,
59-
expectedOutput: &s3.ListBucketsOutput{
60-
Buckets: []*s3.Bucket{
61-
{
62-
Name: aws.String("bucket1"),
63-
},
64-
{
65-
Name: aws.String("bucket2"),
66-
},
67-
},
68-
},
69-
expectedError: nil,
70-
},
71-
{
72-
name: "Error Listing Buckets",
73-
mockResponse: nil,
74-
mockError: errors.New("failed to list buckets"),
75-
expectedOutput: nil,
76-
expectedError: errors.New("failed to list buckets"),
77-
},
78-
}
79-
80-
// Iterate over test cases
81-
for _, testCase := range testCases {
82-
ginkgo.It(testCase.name, func() {
83-
// Arrange mock behavior
84-
mockS3Client.On("ListBuckets", mock.Anything).Return(testCase.mockResponse, testCase.mockError)
85-
86-
// Act
87-
result, err := bucket.ListAvailableBuckets()
88-
89-
// Assert the results
90-
if testCase.expectedError != nil {
91-
gomega.Expect(err).To(gomega.HaveOccurred())
92-
gomega.Expect(err.Error()).To(gomega.Equal(testCase.expectedError.Error()))
93-
} else {
94-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
95-
gomega.Expect(result).To(gomega.Equal(testCase.expectedOutput))
96-
}
97-
98-
// Assert that the mock was called as expected
99-
mockS3Client.AssertExpectations(ginkgo.GinkgoT())
100-
})
101-
}
102-
})
103-
10420
var _ = ginkgo.Describe("ListBucketObjects", func() {
10521

10622
var (
@@ -148,7 +64,6 @@ var _ = ginkgo.Describe("ListBucketObjects", func() {
14864

14965
// Iterate through the test cases
15066
for _, tc := range testCases {
151-
tc := tc // capture the range variable
15267
ginkgo.Context(tc.description, func() {
15368
ginkgo.It("should handle the response correctly", func() {
15469
// Setup mock expectation

code-engine-cos2cos/bucketOperations/bucketOps.go

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type CosSession struct {
4040
}
4141

4242
func NewCosClient(apiKey, resourceInstanceID, serviceEndpoint, region string, authEndpoint ...string) *s3.S3 {
43-
// fmt.Println("Creating cos Client")
4443
var authEndpointVal string
4544
if len(authEndpoint) == 0 {
4645
authEndpointVal = "https://iam.cloud.ibm.com/identity/token"
@@ -120,35 +119,14 @@ func (c *CosSession) CreateIBMCOSSessionTrustedProfile() *s3.S3 {
120119

121120
return client
122121
}
123-
124-
// Function to list all the available buckets for a config.
125-
func (b *Bucket) ListAvailableBuckets() (*s3.ListBucketsOutput, error) {
126-
127-
// Create client
128-
// client := CreateIBMCOSSession()
129-
client := b.Client
130-
// Call Function
131-
d, err := client.ListBuckets(&s3.ListBucketsInput{})
132-
133-
if err != nil {
134-
fmt.Println("Could not list the buckets")
135-
return nil, err
136-
}
137-
return d, nil
138-
}
139-
140122
func (b *Bucket) ListBucketObjects() (*s3.ListObjectsV2Output, error) {
141123
bucketName := b.Name
142-
// fmt.Println("Listing Bucket Objects in Bucket:", bucketName)
143-
// Create client
144-
// client := CreateIBMCOSSession()
145124
client := b.Client
146125

147126
// Call Function
148127
Input := &s3.ListObjectsV2Input{
149128
Bucket: aws.String(bucketName),
150129
}
151-
// fmt.Println("Input object created", Input)
152130
objectList, e := client.ListObjectsV2(Input)
153131

154132
if e != nil {
@@ -161,9 +139,6 @@ func (b *Bucket) ListBucketObjects() (*s3.ListObjectsV2Output, error) {
161139

162140
func (b *Bucket) ListBucketObjectsPagination() (*s3.ListObjectsV2Output, error) {
163141
bucketName := b.Name
164-
// fmt.Println("Listing Bucket Objects in Bucket:", bucketName)
165-
// Create client
166-
// client := CreateIBMCOSSession()
167142
client := b.Client
168143

169144
// Call Function
@@ -211,72 +186,3 @@ func (bucket *Bucket) UploadBytesToBucket(objectKey string, data []byte) error {
211186

212187
return nil
213188
}
214-
215-
// Function to upload a object to a bucket. - Not Tested.
216-
/*
217-
func (b *Bucket) UploadObjectToBucket(object *s3.GetObjectOutput) error {
218-
client := b.Client
219-
220-
var buf bytes.Buffer
221-
_, err := buf.ReadFrom(object.Body)
222-
if err != nil {
223-
log.Fatalf("Unable to read object body: %v", err)
224-
return fmt.Errorf("Unable to read object body: %v", err)
225-
}
226-
227-
_, err = client.PutObject(&s3.PutObjectInput{
228-
Bucket: aws.String(destinationBucket),
229-
Key: aws.String(destinationKey),
230-
Body: bytes.NewReader(buf.Bytes()),
231-
})
232-
if err != nil {
233-
log.Fatalf("Unable to upload object to destination bucket: %v", err)
234-
return fmt.Errorf("Unable to upload object to destination bucket: %v", err)
235-
}
236-
return nil
237-
}
238-
*/
239-
240-
// Returns an error if the upload fails. - Unused
241-
/*
242-
func (b *Bucket) UploadFileToBucket(objectKey string, filePath string) error {
243-
244-
// Create client
245-
// client := CreateIBMCOSSession()
246-
client := b.Client
247-
bucketName := b.Name
248-
249-
// Read object into byte
250-
251-
file, err := os.Open(filePath)
252-
253-
if err != nil {
254-
log.Fatalf("Unable to open file: %v", err)
255-
return err
256-
}
257-
258-
fileInfo, err := file.Stat()
259-
if err != nil {
260-
log.Fatalf("Unable to get file stats: %v", err)
261-
return err
262-
}
263-
fileBytes := make([]byte, fileInfo.Size())
264-
_, err = file.Read(fileBytes)
265-
266-
if err != nil {
267-
log.Fatalf("Unable to read file: %v", err)
268-
return err
269-
}
270-
271-
input := s3.PutObjectInput{
272-
Bucket: aws.String(bucketName),
273-
Key: aws.String(objectKey),
274-
Body: bytes.NewReader(fileBytes),
275-
}
276-
277-
// Call Function to upload (Put) an object
278-
_, _ = client.PutObject(&input)
279-
// fmt.Println(result)
280-
return nil
281-
}
282-
*/

code-engine-cos2cos/bucketOperations/objectOps.go

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ func (b *Bucket) CheckIfTagExists(objectKey string) (bool, error) {
3535
})
3636

3737
if err != nil {
38-
return false, fmt.Errorf("Error getting object tags: %v", err)
38+
return false, fmt.Errorf("error getting object tags: %v", err)
3939

4040
}
4141
tagKeyToCheck := "isInProcessing"
4242

4343
// Iterate through the tags and check if the key exists
4444
for _, tag := range resp.TagSet {
4545
if *tag.Key == tagKeyToCheck {
46-
// fmt.Println(tag)
4746
return true, nil
4847
}
4948
}
@@ -52,7 +51,6 @@ func (b *Bucket) CheckIfTagExists(objectKey string) (bool, error) {
5251

5352
func IsProcessingRequired(res *s3.Object, timestamp time.Time) bool {
5453
compareVal := CompareUpdateTime(res, timestamp)
55-
// fmt.Printf("The time for last process is: %s\nObject last time:%s\n", timestamp.String(), res.LastModified.String())
5654
// A negative value indicates that process is required.
5755
return compareVal > 0
5856
}
@@ -74,62 +72,6 @@ func (b *Bucket) GetObject(objectKey string) (*s3.GetObjectOutput, error) {
7472
return response, nil
7573
}
7674

77-
/*
78-
Function to store the object in a file in local storage
79-
func StoreObject(objectKey string, response *s3.GetObjectOutput) error {
80-
81-
tempFile, err := os.Create(fmt.Sprintf("temp/%s", objectKey))
82-
83-
if err != nil {
84-
log.Fatal(err)
85-
}
86-
87-
// Read from response body
88-
_, err = tempFile.ReadFrom(response.Body)
89-
90-
if err != nil {
91-
return err
92-
}
93-
return nil
94-
}
95-
*/
96-
97-
/*
98-
// Function to get the metadata of an object without getting the object itself - Unused
99-
func (b *Bucket) GetObjectMetadata(objectKey string) (*s3.HeadObjectOutput, error) {
100-
client := b.Client
101-
bucketName := b.Name
102-
103-
input := &s3.HeadObjectInput{
104-
Bucket: aws.String(bucketName),
105-
Key: aws.String(objectKey),
106-
}
107-
108-
result, err := client.HeadObject(input)
109-
if err != nil {
110-
// log.Fatalf("Failed to retrieve metadata: %v", err)
111-
return nil, err
112-
}
113-
114-
// fmt.Println("Metadata for object:", objectKey)
115-
// fmt.Printf("Last Modified: %v\n", result.LastModified)
116-
// fmt.Printf("Size: %d bytes\n", *result.ContentLength)
117-
// fmt.Printf("Content-Type: %s\n", *result.ContentType)
118-
// fmt.Printf("ETag: %s\n", *result.ETag)
119-
120-
// Print custom metadata
121-
if result.Metadata != nil {
122-
fmt.Println("Custom Metadata:")
123-
for key, value := range result.Metadata {
124-
fmt.Printf("%s: %s\n", key, *value)
125-
}
126-
}
127-
128-
return result, nil
129-
}
130-
*/
131-
// test
132-
13375
// Add a tag to the object (for example, a custom tag)
13476
// The tag is added as a key-value pair
13577
func (b *Bucket) AddTag(objectKey, tagKey, tagValue string) error {
@@ -170,6 +112,5 @@ func (b *Bucket) DeleteTag(objectKey, tagKey string) error {
170112
if err != nil {
171113
return fmt.Errorf("failed to delete tag to object: %v", err)
172114
}
173-
// fmt.Printf("Tag Deleted successfully from the object: %s\n", objectKey)
174115
return nil
175116
}

code-engine-cos2cos/bucketOperations/objectOps_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ import (
1313
mockS3 "ibm.com/codeengine/cos2cos/mock"
1414
)
1515

16-
// func TestObjectOps(t *testing.T) {
17-
// gomega.RegisterFailHandler(ginkgo.Fail)
18-
// ginkgo.RunSpecs(t, "ObjectOperations Suite")
19-
// }
20-
2116
var _ = ginkgo.Describe("CompareUpdateTime", func() {
2217
type testCase struct {
2318
name string

code-engine-cos2cos/metadata/local-timestamp.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)