Closed denopink closed 2 years ago
Merging #80 (0218fb9) into main (840a19e) will increase coverage by
0.37%
. The diff coverage is100.00%
.:exclamation: Current head 0218fb9 differs from pull request most recent head fc099bf. Consider uploading reports for the commit fc099bf to get more accurate results
@@ Coverage Diff @@
## main #80 +/- ##
==========================================
+ Coverage 49.30% 49.67% +0.37%
==========================================
Files 19 20 +1
Lines 3235 3259 +24
==========================================
+ Hits 1595 1619 +24
Misses 1469 1469
Partials 171 171
Impacted Files | Coverage Δ | |
---|---|---|
validator.go | 100.00% <100.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 840a19e...fc099bf. Read the comment docs.
@kristinapathak I added some testable examples just to try them out. it's pretty neat
I can take them out if it's too early for doc examples.
@denopink, example looks good! 👍
Overview
related to #25, #78, xmidt-org/scytale#88, xmidt-org/talaria#153 s.t. we want a validation mechanism that is configurable by clients & verifies the spec.
tl;dr
This pr introduces the initial validation framework, where clients supply validators (satisfying the
Validator interface
) toNewMsgTypeValidator
and then used to verify the spec.Explanation
Clients supply validators satisfying: ```go // Validator is a WRP validator that allows access to the Validate function. type Validator interface { Validate(m Message) error } ``` and listing which validators are used on known and unknown msg types (where unknown msg types are handled by `defaultValidator`): ```go var alwaysValid ValidatorFunc = func(msg Message) error { return nil } msgv, err := NewTypeValidator( // Validates found msg types map[MessageType]Validators{SimpleEventMessageType: {alwaysValid}}, // Validates unfound msg types AlwaysInvalid) err = msgv.Validate(Message{Type: SimpleEventMessageType}) // Found success err == nil // True err = msgv.Validate(Message{Type: CreateMessageType}) // Unfound error err == nil // False ``` if a default validator is not provided, all unknown msg type will **fail** by default ```go msgv, err := NewTypeValidator( // Omitted defaultValidator map[MessageType]Validators{SimpleEventMessageType: {alwaysValid}}) err = msgv.Validate(Message{Type: CreateMessageType}) // Unfound error err == nil // False ```Type of Change(s)
- Non-breaking Enhancement - All new and existing tests passed.