This is the same as above, using a pointer receiver for the error type.
(t *testing.T)
| 96 | |
| 97 | // This is the same as above, using a pointer receiver for the error type. |
| 98 | func TestSimpleMigrationForwardPtr(t *testing.T) { |
| 99 | defer errbase.TestingWithEmptyMigrationRegistry()() |
| 100 | |
| 101 | // == Scenario on v1 == |
| 102 | origErr := (*fooErrP)(nil) |
| 103 | errbase.RegisterLeafDecoder(errbase.GetTypeKey(origErr), |
| 104 | func(_ context.Context, _ string, _ []string, _ proto.Message) error { return (*fooErrP)(nil) }) |
| 105 | |
| 106 | // Send the error to v2. |
| 107 | enc := errbase.EncodeError(context.Background(), origErr) |
| 108 | // Clean up, so that type foo becomes unknown. |
| 109 | errbase.RegisterLeafDecoder(errbase.GetTypeKey(origErr), nil) |
| 110 | |
| 111 | // == Scenario on v2 == |
| 112 | // Register the fact that foo was migrated to bar. |
| 113 | errbase.RegisterTypeMigration(myPkgPath, "*errbase_test.fooErrP", (*barErrP)(nil)) |
| 114 | // Register the bar decoder. |
| 115 | errbase.RegisterLeafDecoder(errbase.GetTypeKey((*barErrP)(nil)), |
| 116 | func(_ context.Context, _ string, _ []string, _ proto.Message) error { return (*barErrP)(nil) }) |
| 117 | // Receive the error from v1. |
| 118 | dec := errbase.DecodeError(context.Background(), enc) |
| 119 | // Clean up, so that type bar becomes unknown for further tests. |
| 120 | errbase.RegisterLeafDecoder(errbase.GetTypeKey((*barErrP)(nil)), nil) |
| 121 | |
| 122 | // Main test: check that v2 recognized the foo error from |
| 123 | // v1 and instantiated it as bar. |
| 124 | if _, ok := dec.(*barErrP); !ok { |
| 125 | t.Errorf("migration failed; expected type *barErrP, got %T", dec) |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // Scenario 2: simultaneous migration |
| 130 | // - vA renames foo -> bar |
nothing calls this directly
no test coverage detected
searching dependent graphs…