Closed denopink closed 2 years ago
Merging #82 (e34c963) into main (840a19e) will increase coverage by
1.13%
. The diff coverage is100.00%
.
@@ Coverage Diff @@
## main #82 +/- ##
==========================================
+ Coverage 49.30% 50.43% +1.13%
==========================================
Files 19 21 +2
Lines 3235 3309 +74
==========================================
+ Hits 1595 1669 +74
Misses 1469 1469
Partials 171 171
Impacted Files | Coverage Δ | |
---|---|---|
utf8.go | 88.23% <ø> (-0.66%) |
:arrow_down: |
spec_validator.go | 100.00% <100.00%> (ø) |
|
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...e34c963. Read the comment docs.
I did something silly and this branch is kinda messed up. Easier to create new branch and pr and cherry-pick the desired commits.
Overview
related to #25, #78, xmidt-org/scytale#88, xmidt-org/talaria#153 and builds on top of #80.
Note The diff looks big because we're waiting for #80 , we'll rebase when it's merged.
tl;dr
This pr introduces our wrp
spec validators
built with our validation framework introduced in #80 which only validates the opinionated portions of the spec. Clients can leverage these prebuilt validators to validate their messages.Explanation
* Validates requirements described at https://xmidt.io/docs/wrp/basics/#overarching-guidelines * Validates requirements described at https://xmidt.io/docs/wrp/basics/#locators * Validates message type values * Does not cover validators for a specific message type (future prs) Clients can leverage our prebuilt validators to validate their messages. One set of these validators are our `spec validators`: ```go msgv, err := NewTypeValidator( // Validates found msg types map[MessageType]Validator{ // Validates opinionated portions of the spec SimpleEventMessageType: SpecValidators, // Only validates Source and nothing else SimpleRequestResponseMessageType: SourceValidator, }, // Validates unfound msg types AlwaysInvalid) if err != nil { return } foundErrSuccess1 := msgv.Validate(Message{ Type: SimpleEventMessageType, Source: "MAC:11:22:33:44:55:66", Destination: "MAC:11:22:33:44:55:61", }) // Found success foundErrSuccess2 := msgv.Validate(Message{ Type: SimpleRequestResponseMessageType, Source: "MAC:11:22:33:44:55:66", Destination: "invalid:a-BB-44-55", }) // Found success foundErrFailure := msgv.Validate(Message{ Type: Invalid0MessageType, Source: "invalid:a-BB-44-55", Destination: "invalid:a-BB-44-55", }) // Found error unfoundErrFailure := msgv.Validate(Message{Type: CreateMessageType}) // Unfound error fmt.Println(foundErrSuccess1 == nil, foundErrSuccess2 == nil, foundErrFailure == nil, unfoundErrFailure == nil) // Output: true true false false ```Type of Change(s)
- Non-breaking Enhancement - All new and existing tests passed.