Skip to content

Commit

Permalink
clean up comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Aug 9, 2022
1 parent bf27665 commit 0fd9c64
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 6 additions & 0 deletions r2_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ func (api *API) CreateR2Bucket(ctx context.Context, rc *ResourceContainer, bucke
if rc.Identifier == "" {
return ErrMissingAccountID
}

if bucketName == "" {
return ErrMissingBucketName
}

uri := fmt.Sprintf("/accounts/%s/r2/buckets/%s", rc.Identifier, bucketName)
_, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil)

return err
}

Expand All @@ -33,10 +36,13 @@ func (api *API) DeleteR2Bucket(ctx context.Context, rc *ResourceContainer, bucke
if rc.Identifier == "" {
return ErrMissingAccountID
}

if bucketName == "" {
return ErrMissingBucketName
}

uri := fmt.Sprintf("/accounts/%s/r2/buckets/%s", rc.Identifier, bucketName)
_, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil)

return err
}
11 changes: 4 additions & 7 deletions r2_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package cloudflare
import (
"context"
"fmt"
"github.com/stretchr/testify/assert"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

const testBucketName = "example-bucket"
Expand All @@ -22,16 +23,14 @@ func TestR2_CreateBucket(t *testing.T) {
"errors": [],
"messages": [],
"result": {}
}`) //nolint
}`)
})

// Make sure missing account ID is thrown
err := client.CreateR2Bucket(context.Background(), AccountIdentifier(""), "")
if assert.Error(t, err) {
assert.Equal(t, ErrMissingAccountID, err)
}

// Make sure missing bucket name is thrown
err = client.CreateR2Bucket(context.Background(), AccountIdentifier(testAccountID), "")
if assert.Error(t, err) {
assert.Equal(t, ErrMissingBucketName, err)
Expand All @@ -53,16 +52,14 @@ func TestR2_DeleteBucket(t *testing.T) {
"errors": [],
"messages": [],
"result": {}
}`) //nolint
}`)
})

// Make sure missing account ID is thrown
err := client.DeleteR2Bucket(context.Background(), AccountIdentifier(""), "")
if assert.Error(t, err) {
assert.Equal(t, ErrMissingAccountID, err)
}

// Make sure missing bucket name is thrown
err = client.DeleteR2Bucket(context.Background(), AccountIdentifier(testAccountID), "")
if assert.Error(t, err) {
assert.Equal(t, ErrMissingBucketName, err)
Expand Down

0 comments on commit 0fd9c64

Please sign in to comment.