Skip to content

Commit c6bd3fa

Browse files
feat: add Metadata field to the State Save operation (#323)
* WIP on adding metadata Signed-off-by: Xavier Geerinck <[email protected]> * Add tests for state change Signed-off-by: Xavier Geerinck <[email protected]>
1 parent 13afefe commit c6bd3fa

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

src/types/KeyValuePair.type.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
1313

14-
export type KeyValuePairType= {
14+
import { KeyValueType } from "./KeyValue.type";
15+
16+
export type KeyValuePairType = {
1517
key: string;
1618
value: any;
19+
etag?: string;
20+
metadata?: KeyValueType;
21+
options?: object;
1722
}

test/e2e/grpc/client.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ describe('grpc/client', () => {
158158
});
159159

160160
describe('state', () => {
161+
beforeEach(async () => {
162+
await client.state.delete("state-redis", "key-1");
163+
await client.state.delete("state-redis", "key-2");
164+
await client.state.delete("state-redis", "key-3");
165+
});
166+
161167
it('should be able to save the state', async () => {
162168
await client.state.save('state-redis', [
163169
{
@@ -178,6 +184,34 @@ describe('grpc/client', () => {
178184
expect(res).toEqual('value-1');
179185
});
180186

187+
it('should be able to add metadata, etag and options', async () => {
188+
await client.state.save('state-redis', [
189+
{
190+
key: 'key-1',
191+
value: 'value-1',
192+
etag: "1234",
193+
options: {
194+
"concurrency": "first-write",
195+
"consistency": "strong"
196+
},
197+
metadata: {
198+
hello: "world"
199+
}
200+
},
201+
{
202+
key: 'key-2',
203+
value: 'value-2',
204+
},
205+
{
206+
key: 'key-3',
207+
value: 'value-3',
208+
},
209+
]);
210+
211+
const res = await client.state.get('state-redis', 'key-1');
212+
expect(res).toEqual('value-1');
213+
});
214+
181215
it('should be able to get the state in bulk', async () => {
182216
await client.state.save('state-redis', [
183217
{
@@ -272,6 +306,35 @@ describe('grpc/client', () => {
272306
expect(resTransactionDelete).toEqual('');
273307
expect(resTransactionUpsert).toEqual('my-new-data-with-metadata-1');
274308
});
309+
310+
it('should be able to add metadata, etag and options', async () => {
311+
await client.state.save('state-redis', [
312+
{
313+
key: 'key-1',
314+
value: 'value-1',
315+
etag: "1234",
316+
options: {
317+
"concurrency": "first-write",
318+
"consistency": "strong"
319+
},
320+
metadata: {
321+
hello: "world"
322+
}
323+
},
324+
{
325+
key: 'key-2',
326+
value: 'value-2',
327+
},
328+
{
329+
key: 'key-3',
330+
value: 'value-3',
331+
},
332+
]);
333+
334+
const res = await client.state.get('state-redis', 'key-1');
335+
expect(res).toEqual('value-1');
336+
console.log(res);
337+
});
275338
});
276339

277340
describe('configuration', () => {

test/e2e/http/client.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ describe('http/client', () => {
9090
});
9191

9292
describe('state', () => {
93+
beforeEach(async () => {
94+
await client.state.delete("state-redis", "key-1");
95+
await client.state.delete("state-redis", "key-2");
96+
await client.state.delete("state-redis", "key-3");
97+
});
98+
9399
it('should be able to save the state', async () => {
94100
await client.state.save('state-redis', [
95101
{
@@ -110,6 +116,34 @@ describe('http/client', () => {
110116
expect(res).toEqual('value-1');
111117
});
112118

119+
it('should be able to add metadata, etag and options', async () => {
120+
await client.state.save('state-redis', [
121+
{
122+
key: 'key-1',
123+
value: 'value-1',
124+
etag: "1234",
125+
options: {
126+
"concurrency": "first-write",
127+
"consistency": "strong"
128+
},
129+
metadata: {
130+
hello: "world"
131+
}
132+
},
133+
{
134+
key: 'key-2',
135+
value: 'value-2',
136+
},
137+
{
138+
key: 'key-3',
139+
value: 'value-3',
140+
},
141+
]);
142+
143+
const res = await client.state.get('state-redis', 'key-1');
144+
expect(res).toEqual('value-1');
145+
});
146+
113147
it('should be able to get the state in bulk', async () => {
114148
await client.state.save('state-redis', [
115149
{

0 commit comments

Comments
 (0)