mirror of https://github.com/dapr/go-sdk.git
issue 62 metadata in get state operation (#65)
This commit is contained in:
parent
dcf3ba0751
commit
c368bf0455
|
|
@ -61,7 +61,7 @@ type Client interface {
|
|||
GetState(ctx context.Context, store, key string) (item *StateItem, err error)
|
||||
|
||||
// GetStateWithConsistency retreaves state from specific store using provided state consistency.
|
||||
GetStateWithConsistency(ctx context.Context, store, key string, sc StateConsistency) (item *StateItem, err error)
|
||||
GetStateWithConsistency(ctx context.Context, store, key string, meta map[string]string, sc StateConsistency) (item *StateItem, err error)
|
||||
|
||||
// GetBulkItems retreaves state for multiple keys from specific store.
|
||||
GetBulkItems(ctx context.Context, store string, keys []string, parallelism int32) ([]*StateItem, error)
|
||||
|
|
|
|||
|
|
@ -251,11 +251,11 @@ func (c *GRPCClient) GetBulkItems(ctx context.Context, store string, keys []stri
|
|||
|
||||
// GetState retreaves state from specific store using default consistency option.
|
||||
func (c *GRPCClient) GetState(ctx context.Context, store, key string) (item *StateItem, err error) {
|
||||
return c.GetStateWithConsistency(ctx, store, key, StateConsistencyStrong)
|
||||
return c.GetStateWithConsistency(ctx, store, key, nil, StateConsistencyStrong)
|
||||
}
|
||||
|
||||
// GetStateWithConsistency retreaves state from specific store using provided state consistency.
|
||||
func (c *GRPCClient) GetStateWithConsistency(ctx context.Context, store, key string, sc StateConsistency) (item *StateItem, err error) {
|
||||
func (c *GRPCClient) GetStateWithConsistency(ctx context.Context, store, key string, meta map[string]string, sc StateConsistency) (item *StateItem, err error) {
|
||||
if store == "" {
|
||||
return nil, errors.New("nil store")
|
||||
}
|
||||
|
|
@ -267,6 +267,7 @@ func (c *GRPCClient) GetStateWithConsistency(ctx context.Context, store, key str
|
|||
StoreName: store,
|
||||
Key: key,
|
||||
Consistency: (v1.StateOptions_StateConsistency(sc)),
|
||||
Metadata: meta,
|
||||
}
|
||||
|
||||
result, err := c.protoClient.GetState(c.withAuthToken(ctx), req)
|
||||
|
|
|
|||
|
|
@ -48,6 +48,15 @@ func TestSaveState(t *testing.T) {
|
|||
assert.Equal(t, string(item.Value), data)
|
||||
})
|
||||
|
||||
t.Run("get saved data with consistency", func(t *testing.T) {
|
||||
item, err := testClient.GetStateWithConsistency(ctx, store, key, nil, StateConsistencyStrong)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, item)
|
||||
assert.NotEmpty(t, item.Etag)
|
||||
assert.Equal(t, item.Key, key)
|
||||
assert.Equal(t, string(item.Value), data)
|
||||
})
|
||||
|
||||
t.Run("save data with version", func(t *testing.T) {
|
||||
item := &SetStateItem{
|
||||
Etag: "1",
|
||||
|
|
|
|||
Loading…
Reference in New Issue