-
Notifications
You must be signed in to change notification settings - Fork 1.4k
msp: Expose contract mock for tests #62691
base: main
Are you sure you want to change the base?
Conversation
jac
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice QOL improvement 👍
lib/managedservicesplatform/runtime/contract/mock/contract_mock.go
Outdated
Show resolved
Hide resolved
| type MockError struct { | ||
| error | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this type for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's so that you can distinguish between between the mock failing because contract.ParseEnv failed and the error returned by env.Validate()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest against this - callers should be able to not differentiate between mock errors vs not, unless they DIY it (provide a sentinel error to return)
lib/managedservicesplatform/runtime/contract/mock/contract_mock.go
Outdated
Show resolved
Hide resolved
| t.Helper() | ||
| e, err := contract.ParseEnv(env) | ||
| if err != nil { | ||
| return nil, MockError{err} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A naked error/simply wrapped error is sufficient IMO:
| return nil, MockError{err} | |
| return nil, errors.New(err, "contract.ParseEnv") |
I needed to provide a dummy contract and saw that MSP already had this available but it was private.
This PR makes it public while trying to retain it's original intent.
Test plan
bazel test //lib/managedservicesplatform/runtime/...