MCPcopy Create free account
hub / github.com/cockroachdb/errors / TestMigratedErrorPassingThroughAsUnknown

Function TestMigratedErrorPassingThroughAsUnknown

errbase/migrations_test.go:226–265  ·  view source on GitHub ↗

Scenario 4: migrated error passing through node that does not know about the error type whatsoever. - v2 renames foo -> bar - v2.a, v2.b and v0 are connected: v2.a -> v0 -> v2.b (v0 does not know about error foo at all) - v2.a sends an error to v2.b via v0:

(t *testing.T)

Source from the content-addressed store, hash-verified

224// (v0 does not know about error foo at all)
225// - v2.a sends an error to v2.b via v0:
226func TestMigratedErrorPassingThroughAsUnknown(t *testing.T) {
227 defer errbase.TestingWithEmptyMigrationRegistry()()
228
229 // == Scenario on v2.a ==
230 origErr := barErr{}
231 // Register the fact that foo was migrated to bar.
232 errbase.RegisterTypeMigration(myPkgPath, "errbase_test.fooErr", origErr)
233 // Send the error to v1.
234 enc := errbase.EncodeError(context.Background(), origErr)
235 // Clean up the decoder, so that type becomes unknown for further tests.
236 errbase.RegisterLeafDecoder(errbase.GetTypeKey(origErr), nil)
237 // Erase the migration we have set up above, so that the test
238 // underneath does not know about it.
239 defer errbase.TestingWithEmptyMigrationRegistry()()
240
241 // == Scenario on v1 ==
242 // Receive the error from v2.b. Will decode as opaqueLeaf{}.
243 dec := errbase.DecodeError(context.Background(), enc)
244 // Send the error to v2.b.
245 enc2 := errbase.EncodeError(context.Background(), dec)
246
247 // == Scenario on v2.b ==
248 // Register the fact that foo was migrated to bar.
249 errbase.RegisterTypeMigration(myPkgPath, "errbase_test.fooErr", barErr{})
250 errbase.RegisterLeafDecoder(errbase.GetTypeKey(barErr{}),
251 func(_ context.Context, _ string, _ []string, _ proto.Message) error { return barErr{} })
252 // Receive the error from v1.
253 dec2 := errbase.DecodeError(context.Background(), enc2)
254 // Clean up the decoder, so that type becomes unknown for further tests.
255 errbase.RegisterLeafDecoder(errbase.GetTypeKey(barErr{}), nil)
256 // Erase the migration we have set up above, so that the test
257 // underneath does not know about it.
258 defer errbase.TestingWithEmptyMigrationRegistry()()
259
260 // Main test: check that v2.b recognized the foo error
261 // that was passed from v2.a.
262 if _, ok := dec2.(barErr); !ok {
263 t.Errorf("migration failed; expected type barErr, got %T", dec2)
264 }
265}
266
267// Scenario 5: comparison between migrated and non-migrated errors
268// on 3rd party node that doesn't know about the type.

Callers

nothing calls this directly

Calls 6

RegisterTypeMigrationFunction · 0.92
EncodeErrorFunction · 0.92
RegisterLeafDecoderFunction · 0.92
GetTypeKeyFunction · 0.92
DecodeErrorFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…