Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Avro samples system tests to support both BINARY and JSON encodings, introduces the Province interface for better typing, and ensures proper cleanup of schemas. It also fixes the tests by correctly awaiting the publishAndListen calls. The review feedback recommends using standard type assertions (as Province) instead of passing type arguments directly to fromBuffer and fromString methods, as these methods are not defined as generics in standard Avro typings and could cause compilation issues.
| const result = | ||
| encoding === 'BINARY' | ||
| ? type.fromBuffer<Province>(message.data) | ||
| : type.fromString<Province>(message.data.toString()); |
There was a problem hiding this comment.
Passing type arguments directly to type.fromBuffer and type.fromString (e.g., type.fromBuffer<Province>(...)) is not standard for avro-js or avsc type definitions, as these methods are typically not declared as generic in their typings. This works currently only because avro-js lacks strict typings in this context (making type resolve to any), but it will cause compilation errors if strict typings are introduced or if the project switches to avsc.
Using a standard type assertion (as Province) is safer and more robust.
| const result = | |
| encoding === 'BINARY' | |
| ? type.fromBuffer<Province>(message.data) | |
| : type.fromString<Province>(message.data.toString()); | |
| const result = | |
| encoding === 'BINARY' | |
| ? (type.fromBuffer(message.data) as Province) | |
| : (type.fromString(message.data.toString()) as Province); |
|
|
||
| const reader = avro.parse(fetchedSchema.definition!); | ||
| const result = reader.fromBuffer(message.data) as any; | ||
| const result = reader.fromBuffer<Province>(message.data); |
There was a problem hiding this comment.
Avoid passing type arguments directly to reader.fromBuffer as it is not defined as a generic method in standard Avro typings. Use a standard type assertion (as Province) instead.
| const result = reader.fromBuffer<Province>(message.data); | |
| const result = reader.fromBuffer(message.data) as Province; |
|
This is just preliminary test-run work on this one. |
Description
Fixes unawaited Avro sample system tests, JSON encoding, and schema cleanup.
Impact
Ensures Avro binary and JSON system tests execute and clean up.
Changes
awaitcalls topublishAndListen('BINARY')andpublishAndListen('JSON')inhandwritten/pubsub/system-test/avro-samples.test.ts.topic.createSubscription(subName)instead of callingpubsub.subscription(subName).get()on nonexistent subscriptions.'JSON'Avro messages usingtype.toString/type.fromString(keepingtype.toBuffer/type.fromBufferfor'BINARY').after()schema cleanup soresources.filterForCleanupinspectsISchemaobjects (which carry.name) and deletes matching schemas viapubsub.schema(x.name!).delete().Messageimport and replaceanyannotations with typedISchemaandProvincedefinitions.Testing
build/system-test/avro-samples.test.jsagainst the official Cloud Pub/Sub Emulator (0.8.38): 3 passing (1s).build/system-test/avro-samples.test.jsagainst live Cloud Pub/Sub: 3 passing (28s), and confirmed zero leftover topics, subscriptions, or schemas after cleanup.pnpm --dir handwritten/pubsub test: passed.pnpm --dir handwritten/pubsub exec eslint --no-ignore system-test/avro-samples.test.ts: 0 errors, 0 warnings.Alternatives
publishAndListen('BINARY')andpublishAndListen('JSON')unawaited lets both tests silently pass in 0 ms without testing Avro encoding or surfacing errors.