diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2023-07-10 21:18:12 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2023-07-10 21:22:16 +0300 |
commit | 4c030663459d7120ddbbccd60b3a13844838c542 (patch) | |
tree | 8875b298725c61b66e045e7b127d148b50fa4475 | |
parent | 493d25ee865fa36d4afca8306ddfe34aba53e3e6 (diff) |
Ignore relative paths when asserting error metadata
Some errors include the repository's relative path in the error
metadata and assert the metadata for equality. This is not ideal
as the relative path is an internal storage detail and should not
be asserted against elsewhere as we are now doing in handler tests.
These tests will all fail when the relative path is rewritten. Address
this by overriding the relative path field when constructing intecepted
metadata. This way the key's existence in the error metadata is asserted
but not the actual contents of the key.
It would be better to fix the problem in a less magical way but there's
a large number of tests that are asserting the relative paths for equality.
Fix these tests for now by overriding the value. We can later fix the tests
one by one to not assert the relative path to remove this.
-rw-r--r-- | internal/testhelper/grpc.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/internal/testhelper/grpc.go b/internal/testhelper/grpc.go index 7b372871e..f60110566 100644 --- a/internal/testhelper/grpc.go +++ b/internal/testhelper/grpc.go @@ -133,6 +133,17 @@ func MergeIncomingMetadata(ctx context.Context, md ...metadata.MD) context.Conte // metadata into structured errors via the StructErrUnaryInterceptor and StructErrStreamInterceptor so that we can // test that metadata has been set as expected on the client-side of a gRPC call. func WithInterceptedMetadata(err structerr.Error, key string, value any) structerr.Error { + if key == "relative_path" { + // There are a number of tests that assert the returned error metadata for equality. + // The relative path might be rewritten before the handler which leads to the equality + // checks failing. Override the returned relative path so the actual values are not asserted, + // just that the key is present. + // + // This is not really an ideal fix as this overrides a value magically. To remove this, we'll + // have to adjust every test that is asserting the relative paths to not do so. + value = "OVERRIDDEN_BY_TESTHELPER" + } + return err.WithDetail(&testproto.ErrorMetadata{ Key: []byte(key), Value: []byte(fmt.Sprintf("%v", value)), |