issue 62 metadata in get state operation (#65)

This commit is contained in:
Mark Chmarny 2020-09-17 16:12:47 -07:00 committed by GitHub
parent dcf3ba0751
commit c368bf0455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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",