MCPcopy Index your code
hub / github.com/cockroachdb/errors / TestSimpleMigrationForward

Function TestSimpleMigrationForward

errbase/migrations_test.go:31–60  ·  view source on GitHub ↗

Scenario 1: simple migration, forward direction - v2 renames foo -> bar - v2 and v1 are connected - v1 sends an error to v2.

(t *testing.T)

Source from the content-addressed store, hash-verified

29// - v2 and v1 are connected
30// - v1 sends an error to v2.
31func TestSimpleMigrationForward(t *testing.T) {
32 defer errbase.TestingWithEmptyMigrationRegistry()()
33
34 // == Scenario on v1 ==
35 origErr := fooErr{}
36 errbase.RegisterLeafDecoder(errbase.GetTypeKey(origErr),
37 func(_ context.Context, _ string, _ []string, _ proto.Message) error { return fooErr{} })
38
39 // Send the error to v2.
40 enc := errbase.EncodeError(context.Background(), origErr)
41 // Clean up, so that type foo becomes unknown.
42 errbase.RegisterLeafDecoder(errbase.GetTypeKey(origErr), nil)
43
44 // == Scenario on v2 ==
45 // Register the fact that foo was migrated to bar.
46 errbase.RegisterTypeMigration(myPkgPath, "errbase_test.fooErr", barErr{})
47 // Register the bar decoder.
48 errbase.RegisterLeafDecoder(errbase.GetTypeKey(barErr{}),
49 func(_ context.Context, _ string, _ []string, _ proto.Message) error { return barErr{} })
50 // Receive the error from v1.
51 dec := errbase.DecodeError(context.Background(), enc)
52 // Clean up, so that type bar becomes unknown for further tests.
53 errbase.RegisterLeafDecoder(errbase.GetTypeKey(barErr{}), nil)
54
55 // Main test: check that v2 recognized the foo error from
56 // v1 and instantiated it as bar.
57 if _, ok := dec.(barErr); !ok {
58 t.Errorf("migration failed; expected type barErr, got %T", dec)
59 }
60}
61
62// Scenario 1: simple migration, backward direction
63// - v2 renames foo -> bar

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…