Scenario 3: migrated error passing through - v2 renames foo -> bar - v2.a, v2.b and v1 are connected: v2.a -> v1 -> v2.b - v2.a sends an error to v2.b via v1
(t *testing.T)
| 173 | // - v2.a, v2.b and v1 are connected: v2.a -> v1 -> v2.b |
| 174 | // - v2.a sends an error to v2.b via v1 |
| 175 | func TestMigratedErrorPassingThrough(t *testing.T) { |
| 176 | defer errbase.TestingWithEmptyMigrationRegistry()() |
| 177 | |
| 178 | // == Scenario on v2.a == |
| 179 | origErr := barErr{} |
| 180 | // Register the fact that foo was migrated to bar. |
| 181 | errbase.RegisterTypeMigration(myPkgPath, "errbase_test.fooErr", origErr) |
| 182 | // Send the error to v1. |
| 183 | enc := errbase.EncodeError(context.Background(), origErr) |
| 184 | // Clean up the decoder, so that type becomes unknown for further tests. |
| 185 | errbase.RegisterLeafDecoder(errbase.GetTypeKey(origErr), nil) |
| 186 | // Erase the migration we have set up above, so that the test |
| 187 | // underneath does not know about it. |
| 188 | defer errbase.TestingWithEmptyMigrationRegistry()() |
| 189 | |
| 190 | // == Scenario on v1 == |
| 191 | errbase.RegisterLeafDecoder(errbase.GetTypeKey(fooErr{}), |
| 192 | func(_ context.Context, _ string, _ []string, _ proto.Message) error { return fooErr{} }) |
| 193 | // Receive the error from v2.b. |
| 194 | dec := errbase.DecodeError(context.Background(), enc) |
| 195 | // Send the error to v2.b. |
| 196 | enc2 := errbase.EncodeError(context.Background(), dec) |
| 197 | // Clean up, so that type foo becomes unknown. |
| 198 | errbase.RegisterLeafDecoder(errbase.GetTypeKey(fooErr{}), nil) |
| 199 | |
| 200 | // == Scenario on v2.b == |
| 201 | // Register the fact that foo was migrated to bar. |
| 202 | errbase.RegisterTypeMigration(myPkgPath, "errbase_test.fooErr", barErr{}) |
| 203 | errbase.RegisterLeafDecoder(errbase.GetTypeKey(barErr{}), |
| 204 | func(_ context.Context, _ string, _ []string, _ proto.Message) error { return barErr{} }) |
| 205 | // Receive the error from v1. |
| 206 | dec2 := errbase.DecodeError(context.Background(), enc2) |
| 207 | // Clean up the decoder, so that type becomes unknown for further tests. |
| 208 | errbase.RegisterLeafDecoder(errbase.GetTypeKey(barErr{}), nil) |
| 209 | // Erase the migration we have set up above, so that the test |
| 210 | // underneath does not know about it. |
| 211 | defer errbase.TestingWithEmptyMigrationRegistry()() |
| 212 | |
| 213 | // Main test: check that v2.b recognized the foo error |
| 214 | // that was passed from v2.a. |
| 215 | if _, ok := dec2.(barErr); !ok { |
| 216 | t.Errorf("migration failed; expected type barErr, got %T", dec2) |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | // Scenario 4: migrated error passing through node that |
| 221 | // does not know about the error type whatsoever. |
nothing calls this directly
no test coverage detected
searching dependent graphs…