Skip to content

Commit

Permalink
Merge pull request #137 from microsoft/bugfix/backing-store-nil
Browse files Browse the repository at this point in the history
- fixes nullability issue with in memory backing store
  • Loading branch information
baywet authored Jan 17, 2024
2 parents 8266e41 + 504f5f5 commit 6f6c124
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [1.5.5] - 2024-01-17

### Changed

- Fixed a bug where reseting properties to null would be impossible with the in memory backing store. [microsoftgraph/msgraph-sdk-go#643](https://github.com/microsoftgraph/msgraph-sdk-go/issues/643)

## [1.5.4] - 2024-01-16

### Changed
Expand Down
6 changes: 4 additions & 2 deletions store/inmemory_backing_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package store

import (
"errors"
"github.com/google/uuid"
"reflect"
"strings"

"github.com/google/uuid"
)

// BackingStoreSubscriber is a function signature for a listener to any changes to a backing store
Expand Down Expand Up @@ -97,7 +98,8 @@ func (i *InMemoryBackingStore) Enumerate() map[string]interface{} {
func (i *InMemoryBackingStore) EnumerateKeysForValuesChangedToNil() []string {
keys := make([]string, 0)
for k, v := range i.store {
if i.changedValues[k] && v == nil {
valueOfV := reflect.ValueOf(v)
if i.changedValues[k] && (v == nil || valueOfV.Kind() == reflect.Ptr && valueOfV.IsNil()) {
keys = append(keys, k)
}
}
Expand Down
14 changes: 12 additions & 2 deletions store/inmemory_backing_store_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package store

import (
"reflect"
"testing"

"github.com/google/uuid"
"github.com/microsoft/kiota-abstractions-go/serialization"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)

func TestSetAndGetsValuesFromStore(t *testing.T) {
Expand Down Expand Up @@ -204,6 +205,15 @@ func TestReplaceStruct(t *testing.T) {
assert.True(t, reflect.DeepEqual(curr, memoryStore.Enumerate()["key"]))
}

func TestItConsidersSettingNullAsAChange(t *testing.T) {
testEntityInstance := NewTestEntity()
testEntityInstance.GetBackingStore().SetInitializationCompleted(true)
testEntityInstance.GetBackingStore().SetReturnOnlyChangedValues(true)
testEntityInstance.SetId(nil)
assert.Equal(t, 1, len(testEntityInstance.GetBackingStore().Enumerate()))
assert.Equal(t, []string{"id"}, testEntityInstance.GetBackingStore().EnumerateKeysForValuesChangedToNil())
}

type testEntity struct {
// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
additionalData map[string]interface{}
Expand Down

0 comments on commit 6f6c124

Please sign in to comment.