Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ezilber-akamai committed Nov 26, 2024
1 parent c949a70 commit 8cc7182
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 19 deletions.
4 changes: 2 additions & 2 deletions object_storage_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ type ObjectStorageBucketAccess struct {
type ObjectStorageBucketContent struct {
Data []ObjectStorageBucketContentData `json:"data"`
IsTruncated bool `json:"is_truncated"`
NextMarker string `json:"next_marker"`
NextMarker *string `json:"next_marker"`
}

// ObjectStorageBucketContentData holds the data of the content of an ObjectStorageBucket
type ObjectStorageBucketContentData struct {
Etag string `json:"etag"`
LastModified *time.Time `json:"last_modified"`
LastModified *time.Time `json:"-"`
Name string `json:"name"`
Owner string `json:"owner"`
Size int `json:"size"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ interactions:
body: ""
form: {}
headers: {}
url: https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=3k08iWghDDdbt6HOy%2BB6PkOLGdM%3D&Expires=1732655208&AWSAccessKeyID=SANITIZED
url: https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=gksQV4gasjlqHmPgfFuhJ1OCIWE%3D&Expires=1732658402&AWSAccessKeyID=SANITIZED
method: DELETE
response:
body: ""
headers:
Connection:
- keep-alive
X-Amz-Request-Id:
- tx00000d7d10dd6dc867302-0067463701-f1fb4c7f-default
- tx00000a41cad539cfe8a29-006746437a-f1fed6ce-default
status: 204 No Content
code: 204
duration: ""
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interactions:
headers:
Content-Type:
- text/plain
url: https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=EbNJutN9AYagVYExChZtKPdi%2FXY%3D&Expires=1732655201&AWSAccessKeyID=SANITIZED
url: https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=2hta9srwrUWmNKyy3hyslnB2Qqw%3D&Expires=1732658396&AWSAccessKeyID=SANITIZED
method: PUT
response:
body: ""
Expand All @@ -21,7 +21,7 @@ interactions:
Etag:
- '"7f2ababa423061c509f4923dd04b6cf1"'
X-Amz-Request-Id:
- tx000007243d56a3dd2edbc-00674636f9-f2dd5de0-default
- tx0000075aece07f7f76744-0067464375-f3ff40d9-default
status: 200 OK
code: 200
duration: ""
26 changes: 13 additions & 13 deletions test/integration/fixtures/TestObjectStorageObject_Smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Tue, 26 Nov 2024 21:00:39 GMT
- Tue, 26 Nov 2024 21:53:55 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand Down Expand Up @@ -77,7 +77,7 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/go-bucket-test-def/object-url
method: POST
response:
body: '{"url": "https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=EbNJutN9AYagVYExChZtKPdi%2FXY%3D&Expires=1732655201&AWSAccessKeyID=SANITIZED",
body: '{"url": "https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=2hta9srwrUWmNKyy3hyslnB2Qqw%3D&Expires=1732658396&AWSAccessKeyID=SANITIZED",
"exists": false}'
headers:
Access-Control-Allow-Credentials:
Expand All @@ -97,13 +97,13 @@ interactions:
Connection:
- keep-alive
Content-Length:
- "189"
- "187"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Tue, 26 Nov 2024 21:00:41 GMT
- Tue, 26 Nov 2024 21:53:57 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand Down Expand Up @@ -165,7 +165,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Tue, 26 Nov 2024 21:00:42 GMT
- Tue, 26 Nov 2024 21:53:58 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand Down Expand Up @@ -202,7 +202,7 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/go-bucket-test-def/object-list
method: GET
response:
body: '{"data": [{"name": "test", "size": 10, "last_modified": "2018-01-02T03:04:05.608Z",
body: '{"data": [{"name": "test", "size": 10, "last_modified": "2018-01-02T03:04:05.281Z",
"etag": "7f2ababa423061c509f4923dd04b6cf1", "owner": "640757b5-ebe9-45b1-abd5-581f215ef89e"}],
"next_marker": null, "is_truncated": false}'
headers:
Expand All @@ -229,7 +229,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Tue, 26 Nov 2024 21:00:44 GMT
- Tue, 26 Nov 2024 21:53:59 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand Down Expand Up @@ -291,7 +291,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Tue, 26 Nov 2024 21:00:45 GMT
- Tue, 26 Nov 2024 21:54:00 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand Down Expand Up @@ -354,7 +354,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Tue, 26 Nov 2024 21:00:46 GMT
- Tue, 26 Nov 2024 21:54:01 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand Down Expand Up @@ -391,7 +391,7 @@ interactions:
url: https://api.linode.com/v4beta/object-storage/buckets/us-east-1/go-bucket-test-def/object-url
method: POST
response:
body: '{"url": "https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=3k08iWghDDdbt6HOy%2BB6PkOLGdM%3D&Expires=1732655208&AWSAccessKeyID=SANITIZED",
body: '{"url": "https://us-east-1.linodeobjects.com:443/go-bucket-test-def/test?Signature=gksQV4gasjlqHmPgfFuhJ1OCIWE%3D&Expires=1732658402&AWSAccessKeyID=SANITIZED",
"exists": true}'
headers:
Access-Control-Allow-Credentials:
Expand All @@ -411,13 +411,13 @@ interactions:
Connection:
- keep-alive
Content-Length:
- "188"
- "186"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Tue, 26 Nov 2024 21:00:48 GMT
- Tue, 26 Nov 2024 21:54:02 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand Down Expand Up @@ -478,7 +478,7 @@ interactions:
Content-Type:
- application/json
Expires:
- Tue, 26 Nov 2024 21:00:52 GMT
- Tue, 26 Nov 2024 21:54:13 GMT
Pragma:
- no-cache
Strict-Transport-Security:
Expand Down
13 changes: 13 additions & 0 deletions test/unit/fixtures/object_storage_buckets_object_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"data": [
{
"etag": "9f254c71e28e033bf9e0e5262e3e72ab",
"last_modified": "2019-01-01T01:23:45",
"name": "example",
"owner": "bfc70ab2-e3d4-42a4-ad55-83921822270c",
"size": 123
}
],
"is_truncated": false,
"next_marker": null
}
24 changes: 24 additions & 0 deletions test/unit/object_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package unit

import (
"context"
"github.com/stretchr/testify/assert"
"testing"

"github.com/jarcoal/httpmock"
Expand All @@ -20,3 +21,26 @@ func TestObjectStorage_Cancel(t *testing.T) {
t.Fatal(err)
}
}

func TestObjectStorage_ObjectList(t *testing.T) {
fixtureData, err := fixtures.GetFixture("object_storage_buckets_object_list")
assert.NoError(t, err)

var base ClientBaseCase
base.SetUp(t)
defer base.TearDown(t)

base.MockGet("object-storage/buckets/us-east/bucket-name/object-list", fixtureData)

content, err := base.Client.ListObjectStorageBucketContents(context.Background(), "us-east", "bucket-name", nil)
if err != nil {
t.Fatalf("Error getting content: %v", err)
}

assert.Equal(t, false, content.IsTruncated)
assert.Nil(t, content.NextMarker)
assert.Equal(t, "example", content.Data[0].Name)
assert.Equal(t, "bfc70ab2-e3d4-42a4-ad55-83921822270c", content.Data[0].Owner)
assert.Equal(t, 123, content.Data[0].Size)
assert.Equal(t, "9f254c71e28e033bf9e0e5262e3e72ab", content.Data[0].Etag)
}

0 comments on commit 8cc7182

Please sign in to comment.