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

Function TestSimpleMigrationBackward

errbase/migrations_test.go:66–95  ·  view source on GitHub ↗

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

(t *testing.T)

Source from the content-addressed store, hash-verified

64// - v2 and v1 are connected
65// - v2 sends an error to v1.
66func TestSimpleMigrationBackward(t *testing.T) {
67 defer errbase.TestingWithEmptyMigrationRegistry()()
68
69 // == Scenario on v2 ==
70 origErr := barErr{}
71 // Register the fact that foo was migrated to bar.
72 errbase.RegisterTypeMigration(myPkgPath, "errbase_test.fooErr", origErr)
73 // Send the error to v1.
74 enc := errbase.EncodeError(context.Background(), origErr)
75 // Clean up the decoder, so that type becomes unknown for further tests.
76 errbase.RegisterLeafDecoder(errbase.GetTypeKey(origErr), nil)
77 // Erase the migration we have set up above, so that the test
78 // underneath does not know about it.
79 defer errbase.TestingWithEmptyMigrationRegistry()()
80
81 // == Scenario on v1 ==
82 errbase.RegisterLeafDecoder(errbase.GetTypeKey(fooErr{}),
83 func(_ context.Context, _ string, _ []string, _ proto.Message) error { return fooErr{} })
84
85 // Receive the error from v2.
86 dec := errbase.DecodeError(context.Background(), enc)
87 // Clean up, so that type foo becomes unknown.
88 errbase.RegisterLeafDecoder(errbase.GetTypeKey(fooErr{}), nil)
89
90 // Main test: check that v1 recognized the foo error from
91 // v2 and instantiated it as foo.
92 if _, ok := dec.(fooErr); !ok {
93 t.Errorf("migration failed; expected type fooErr, got %T", dec)
94 }
95}
96
97// This is the same as above, using a pointer receiver for the error type.
98func TestSimpleMigrationForwardPtr(t *testing.T) {

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…