Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed ThroughputOptions to use azcore Etag #15900

Merged
merged 1 commit into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/data/azcosmos/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func Example() {
log.Fatal(err)
}

var itemResponseBody map[string]interface{}
var itemResponseBody map[string]string
err = json.Unmarshal(itemResponse.Value, &itemResponseBody)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -189,7 +189,7 @@ func Example() {
log.Fatal(err)
}

var itemResponseBody map[string]interface{}
var itemResponseBody map[string]string
err = json.Unmarshal(itemResponse.Value, &itemResponseBody)
if err != nil {
log.Fatal(err)
Expand Down
18 changes: 11 additions & 7 deletions sdk/data/azcosmos/throughput_request_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@

package azcosmos

import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
)

// ThroughputOptions includes options for throughput operations.
type ThroughputOptions struct {
IfMatchEtag string
IfNoneMatchEtag string
IfMatchEtag *azcore.ETag
IfNoneMatchEtag *azcore.ETag
}

func (options *ThroughputOptions) toHeaders() *map[string]string {
if options.IfMatchEtag == "" && options.IfNoneMatchEtag == "" {
if options.IfMatchEtag == nil && options.IfNoneMatchEtag == nil {
return nil
}

headers := make(map[string]string)
if options.IfMatchEtag != "" {
headers[headerIfMatch] = options.IfMatchEtag
if options.IfMatchEtag != nil {
headers[headerIfMatch] = string(*options.IfMatchEtag)
}
if options.IfNoneMatchEtag != "" {
headers[headerIfNoneMatch] = options.IfNoneMatchEtag
if options.IfNoneMatchEtag != nil {
headers[headerIfNoneMatch] = string(*options.IfNoneMatchEtag)
}
return &headers
}
15 changes: 10 additions & 5 deletions sdk/data/azcosmos/throughput_request_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package azcosmos

import (
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
)

func TestThroughputRequestOptionsToHeaders(t *testing.T) {
Expand All @@ -13,18 +15,21 @@ func TestThroughputRequestOptionsToHeaders(t *testing.T) {
t.Error("toHeaders should return nil")
}

options.IfMatchEtag = "etag"
options.IfNoneMatchEtag = "noneetag"
etag := azcore.ETag("etag")
noneetag := azcore.ETag("noneetag")
options.IfMatchEtag = &etag
options.IfNoneMatchEtag = &noneetag

header := options.toHeaders()
if header == nil {
if *header == nil {
t.Error("toHeaders should return non-nil")
}

headers := *header
if headers[headerIfMatch] != options.IfMatchEtag {
if headers[headerIfMatch] != string(*options.IfMatchEtag) {
t.Errorf("IfMatchEtag not set matching expected %v got %v", options.IfMatchEtag, headers[headerIfMatch])
}
if headers[headerIfNoneMatch] != options.IfNoneMatchEtag {
if headers[headerIfNoneMatch] != string(*options.IfNoneMatchEtag) {
t.Errorf("IfNoneMatchEtag not set matching expected %v got %v", options.IfNoneMatchEtag, headers[headerIfNoneMatch])
}
}