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

[Cosmos DB] [API Review] Move to azcore 0.20 and fit and finish #15927

Merged
merged 9 commits 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
15 changes: 7 additions & 8 deletions sdk/data/azcosmos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ properties := azcosmos.ContainerProperties{
}

throughput := azcosmos.NewManualThroughputProperties(400)
response, err := database.CreateContainer(context, properties, &CreateContainerOptions{ThroughputProperties: throughput})
response, err := database.CreateContainer(context, properties, &CreateContainerOptions{ThroughputProperties: &throughput})
handle(err)
container := resp.ContainerProperties.Container
```

### CRUD operation on Items
Expand All @@ -92,21 +91,21 @@ item := map[string]string{
}

// Create partition key
container := client.GetContainer(dbName, containerName)
pk, err := azcosmos.NewPartitionKey("1")
container, err := client.NewContainer(dbName, containerName)
handle(err)
pk := azcosmos.NewPartitionKeyString("1")

// Create an item
itemResponse, err := container.CreateItem(context, &pk, item, nil)
itemResponse, err := container.CreateItem(context, pk, item, nil)
handle(err)

itemResponse, err = container.ReadItem(context, &pk, "1", nil)
itemResponse, err = container.ReadItem(context, pk, "1", nil)
handle(err)

itemResponse, err = container.ReplaceItem(context, &pk, "1", item, nil)
itemResponse, err = container.ReplaceItem(context, pk, "1", item, nil)
handle(err)

itemResponse, err = container.DeleteItem(context, &pk, "1", nil)
itemResponse, err = container.DeleteItem(context, pk, "1", nil)
handle(err)
```

Expand Down
50 changes: 25 additions & 25 deletions sdk/data/azcosmos/async_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import (

func Test_set(t *testing.T) {
key := "someKey"
expectedValue := ContainerProperties{Id: "someId"}
expectedValue := ContainerProperties{ID: "someId"}

cache := newAsyncCache()

cache.setValue(key, expectedValue)
value, _ := cache.getValue(key)
containerProps, _ := value.(ContainerProperties)
assert.Equal(t, expectedValue.Id, containerProps.Id)
assert.Equal(t, expectedValue.ID, containerProps.ID)
}

func Test_setAsync(t *testing.T) {
key := "someKeyAsync"
expectedValue := ContainerProperties{Id: "someIdAsync"}
expectedValue := ContainerProperties{ID: "someIdAsync"}

cache := newAsyncCache()

Expand All @@ -38,13 +38,13 @@ func Test_setAsync(t *testing.T) {
_ = cache.set(key, f, context.Background())
value, _ := cache.getValue(key)
containerProps, _ := value.(ContainerProperties)
assert.Equal(t, expectedValue.Id, containerProps.Id)
assert.Equal(t, expectedValue.ID, containerProps.ID)
}

func Test_getAsync_not_obsolete(t *testing.T) {
key := "testAsyncKey"
expectedValue0 := ContainerProperties{Id: "0"}
expectedValue1 := ContainerProperties{Id: "1"}
expectedValue0 := ContainerProperties{ID: "0"}
expectedValue1 := ContainerProperties{ID: "1"}
f1Called := false
f2Called := false

Expand Down Expand Up @@ -80,17 +80,17 @@ func Test_getAsync_not_obsolete(t *testing.T) {
assert.False(t, f2Called)

containerProps, _ := value.(ContainerProperties)
assert.Equal(t, expectedValue1.Id, containerProps.Id)
assert.Equal(t, expectedValue1.ID, containerProps.ID)

containerProps2, _ := value2.(ContainerProperties)
assert.Equal(t, expectedValue1.Id, containerProps2.Id)
assert.Equal(t, expectedValue1.ID, containerProps2.ID)
}

func Test_getAsync_obsolete(t *testing.T) {
key := "testAsyncObsoleteKey"
expectedValue0 := ContainerProperties{Id: "0"}
expectedValue1 := ContainerProperties{Id: "1"}
expectedValue2 := ContainerProperties{Id: "2"}
expectedValue0 := ContainerProperties{ID: "0"}
expectedValue1 := ContainerProperties{ID: "1"}
expectedValue2 := ContainerProperties{ID: "2"}
f1Called := false
f2Called := false

Expand Down Expand Up @@ -127,15 +127,15 @@ func Test_getAsync_obsolete(t *testing.T) {

assert.True(t, f1Called)
assert.True(t, f2Called)
assert.Equal(t, expectedValue2.Id, containerProps.Id)
assert.Equal(t, expectedValue2.Id, containerProps2.Id)
assert.Equal(t, expectedValue2.ID, containerProps.ID)
assert.Equal(t, expectedValue2.ID, containerProps2.ID)
}

func Test_getAsync_obsolete_with_error(t *testing.T) {
key := "testAsyncObsoleteKey"
expectedValue0 := ContainerProperties{Id: "0"}
expectedValue1 := ContainerProperties{Id: "1"}
expectedValue2 := ContainerProperties{Id: "2"}
expectedValue0 := ContainerProperties{ID: "0"}
expectedValue1 := ContainerProperties{ID: "1"}
expectedValue2 := ContainerProperties{ID: "2"}
f1Called := false
f2Called := false

Expand Down Expand Up @@ -176,9 +176,9 @@ func Test_getAsync_obsolete_with_error(t *testing.T) {

func Test_getAsync_obsolete_with_context_error(t *testing.T) {
key := "testAsyncObsoleteKey"
expectedValue0 := ContainerProperties{Id: "0"}
expectedValue1 := ContainerProperties{Id: "1"}
expectedValue2 := ContainerProperties{Id: "2"}
expectedValue0 := ContainerProperties{ID: "0"}
expectedValue1 := ContainerProperties{ID: "1"}
expectedValue2 := ContainerProperties{ID: "2"}
f1Called := false
f2Called := false

Expand Down Expand Up @@ -221,14 +221,14 @@ func Test_getAsync_obsolete_with_context_error(t *testing.T) {

func Test_remove(t *testing.T) {
key := "someKeyToRemove"
expectedValue := ContainerProperties{Id: "someIdToRemove"}
expectedValue := ContainerProperties{ID: "someIdToRemove"}

cache := newAsyncCache()

cache.setValue(key, expectedValue)
value, _ := cache.getValue(key)
containerProps, _ := value.(ContainerProperties)
assert.Equal(t, expectedValue.Id, containerProps.Id)
assert.Equal(t, expectedValue.ID, containerProps.ID)

cache.remove(key)

Expand All @@ -239,21 +239,21 @@ func Test_remove(t *testing.T) {

func Test_clear(t *testing.T) {
key := "someKeyToClear"
expectedValue := ContainerProperties{Id: "someIdToDelete"}
expectedValue := ContainerProperties{ID: "someIdToDelete"}
key2 := "someKeyToClear2"
expectedValue2 := ContainerProperties{Id: "someIdToDelete2"}
expectedValue2 := ContainerProperties{ID: "someIdToDelete2"}

cache := newAsyncCache()

cache.setValue(key, expectedValue)
value, _ := cache.getValue(key)
containerProps, _ := value.(ContainerProperties)
assert.Equal(t, expectedValue.Id, containerProps.Id)
assert.Equal(t, expectedValue.ID, containerProps.ID)

cache.setValue(key2, expectedValue2)
value2, _ := cache.getValue(key2)
containerProps2, _ := value2.(ContainerProperties)
assert.Equal(t, expectedValue2.Id, containerProps2.Id)
assert.Equal(t, expectedValue2.ID, containerProps2.ID)

cache.clear()

Expand Down
Loading