-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: Initial WRP Validation Framework #80
FR: Initial WRP Validation Framework #80
Commits on May 24, 2022
-
Configuration menu - View commit details
-
Copy full SHA for dfeee98 - Browse repository at this point
Copy the full SHA dfeee98View commit details
Commits on May 25, 2022
-
Initial WRP Validation Framework
## Overview related to xmidt-org#25, xmidt-org#78, xmidt-org/scytale#88, xmidt-org/talaria#153 s.t. we want a validation mechanism that is configurable by the application & verifies the spec. ### tl;rd This pr introduces the initial validation framework, where applications supply validators (satisfying the `Validator interface`) to `NewMsgTypeValidator` and then used to verify the spec. <details> <summary> Explanation</summary> Apps 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 alwaysValidMsg ValidatorFunc = func(msg Message) error { return nil } msgv, err := NewMsgTypeValidator( // Validates known msg types m: map[MessageType]Validators{SimpleEventMessageType: {alwaysValidMsg}}, // Validates unknown msg types defaultValidator: alwaysValidMsg) err = msgv.Validate(Message{Type: SimpleEventMessageType}) // Known msg type err == nil // True err = msgv.Validate(Message{Type: CreateMessageType}) // Unknown msg type, uses defaultValidator err == nil // True ``` if a default validator is not provided, all unknown msg type will **fail** by default ```go var alwaysValidMsg ValidatorFunc = func(msg Message) error { return nil } msgv, err := NewMsgTypeValidator( // Omitted defaultValidator m: map[MessageType]Validators{SimpleEventMessageType: {alwaysInvalidMsg()}}) err = msgv.Validate(Message{Type: CreateMessageType}) err != nil // True ``` </details> <details> <summary>Type of Change(s)</summary> - Non-breaking Enhancement - All new and existing tests passed. </details> <details> <summary>Module Unit Testing: [PASSING]</summary> </details> <details> <summary>PR Affecting Unit Testing: validator_test.go [PASSING]</summary> ```console Running tool: /usr/local/bin/go test -timeout 30s -run ^(TestHelperValidators|TestMsgTypeValidator)$ github.com/xmidt-org/wrp-go/v3 === RUN TestHelperValidators === RUN TestHelperValidators/alwaysInvalidMsg --- PASS: TestHelperValidators (0.00s) --- PASS: TestHelperValidators/alwaysInvalidMsg (0.00s) === RUN TestMsgTypeValidator === RUN TestMsgTypeValidator/MsgTypeValidator_validate === RUN TestMsgTypeValidator/MsgTypeValidator_validate/known_message_type === RUN TestMsgTypeValidator/MsgTypeValidator_validate/unknown_message_type_with_provided_default_Validator === RUN TestMsgTypeValidator/MsgTypeValidator_validate/known_message_type_with_a_failing_Validator === RUN TestMsgTypeValidator/MsgTypeValidator_validate/unknown_message_type_without_provided_default_Validator === RUN TestMsgTypeValidator/MsgTypeValidator_factory === RUN TestMsgTypeValidator/MsgTypeValidator_factory/with_provided_default_Validator === RUN TestMsgTypeValidator/MsgTypeValidator_factory/without_provided_default_Validator === RUN TestMsgTypeValidator/MsgTypeValidator_factory/empty_list_of_message_type_Validators === RUN TestMsgTypeValidator/MsgTypeValidator_factory/empty_value_'m'_map[MessageType]Validators --- PASS: TestMsgTypeValidator (0.00s) --- PASS: TestMsgTypeValidator/MsgTypeValidator_validate (0.00s) --- PASS: TestMsgTypeValidator/MsgTypeValidator_validate/known_message_type (0.00s) --- PASS: TestMsgTypeValidator/MsgTypeValidator_validate/unknown_message_type_with_provided_default_Validator (0.00s) --- PASS: TestMsgTypeValidator/MsgTypeValidator_validate/known_message_type_with_a_failing_Validator (0.00s) --- PASS: TestMsgTypeValidator/MsgTypeValidator_validate/unknown_message_type_without_provided_default_Validator (0.00s) --- PASS: TestMsgTypeValidator/MsgTypeValidator_factory (0.00s) --- PASS: TestMsgTypeValidator/MsgTypeValidator_factory/with_provided_default_Validator (0.00s) --- PASS: TestMsgTypeValidator/MsgTypeValidator_factory/without_provided_default_Validator (0.00s) --- PASS: TestMsgTypeValidator/MsgTypeValidator_factory/empty_list_of_message_type_Validators (0.00s) --- PASS: TestMsgTypeValidator/MsgTypeValidator_factory/empty_value_'m'_map[MessageType]Validators (0.00s) PASS ok github.com/xmidt-org/wrp-go/v3 0.303s > Test run finished at 5/25/2022, 11:39:22 AM < ``` </details>
Configuration menu - View commit details
-
Copy full SHA for 7f8bad0 - Browse repository at this point
Copy the full SHA 7f8bad0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 9319c12 - Browse repository at this point
Copy the full SHA 9319c12View commit details -
Configuration menu - View commit details
-
Copy full SHA for 209ffdb - Browse repository at this point
Copy the full SHA 209ffdbView commit details -
convert alwaysInvalidMsg to literal func
simplifies the usage of alwaysInvalidMsg
Configuration menu - View commit details
-
Copy full SHA for ddd0acf - Browse repository at this point
Copy the full SHA ddd0acfView commit details -
Configuration menu - View commit details
-
Copy full SHA for a2a4093 - Browse repository at this point
Copy the full SHA a2a4093View commit details -
Return `ErrInvalidMsgTypeValidator` and `ErrInvalidMsgType` without additional details. We can add those error details downstream later
Configuration menu - View commit details
-
Copy full SHA for f5a2e90 - Browse repository at this point
Copy the full SHA f5a2e90View commit details
Commits on May 26, 2022
-
Configuration menu - View commit details
-
Copy full SHA for eb5bf9b - Browse repository at this point
Copy the full SHA eb5bf9bView commit details -
Configuration menu - View commit details
-
Copy full SHA for afa08cb - Browse repository at this point
Copy the full SHA afa08cbView commit details -
Configuration menu - View commit details
-
Copy full SHA for 8cb0fa7 - Browse repository at this point
Copy the full SHA 8cb0fa7View commit details -
Configuration menu - View commit details
-
Copy full SHA for 10afaa2 - Browse repository at this point
Copy the full SHA 10afaa2View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1923ec7 - Browse repository at this point
Copy the full SHA 1923ec7View commit details -
Updated defaultValidator to work as a variadic for multi-default supp…
…ort & added examples
Configuration menu - View commit details
-
Copy full SHA for 98c4b4a - Browse repository at this point
Copy the full SHA 98c4b4aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 3197568 - Browse repository at this point
Copy the full SHA 3197568View commit details -
Merge branch 'denopink/FR-WRPValidationFramework' of https://github.c…
…om/denopink/wrp-go into denopink/FR-WRPValidationFramework
Configuration menu - View commit details
-
Copy full SHA for 1ee6c2e - Browse repository at this point
Copy the full SHA 1ee6c2eView commit details
Commits on Jun 1, 2022
-
Squash: examples, docs, multierr updates
update examples Doc/var update Add test for `Nil default Validators` edge case update examples output doc update Updates based on PR review * exported alwaysValid * decoupled data structures leveraging `Validators` to `Validator` * added validateValidator Add multierr to Validator
Configuration menu - View commit details
-
Copy full SHA for 793d6f4 - Browse repository at this point
Copy the full SHA 793d6f4View commit details
Commits on Jun 3, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 22ca097 - Browse repository at this point
Copy the full SHA 22ca097View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5ff49e3 - Browse repository at this point
Copy the full SHA 5ff49e3View commit details
Commits on Jun 7, 2022
-
* converted remaining `Validators` to `Validator` * remove func `validateValidator` * move nil checks to `Validate` func * remove Test struct * add new unexported field to check if `TypeValidato` is valid * add func `IsBad` to TypeValidato to say whether `TypeValidato` is valid * update tests for testAlwaysInvalid and testAlwaysValid * update tests names for `TestTypeValidator` * add tests for `Validators`
Configuration menu - View commit details
-
Copy full SHA for 1f1aa67 - Browse repository at this point
Copy the full SHA 1f1aa67View commit details
Commits on Jun 8, 2022
-
* [misunderstanding] Remove unexported field `isbad` from `TypeValidator` and its references * [misunderstanding] Remove `IsBad` func from `TypeValidator` * Use `assert.Zero/NotZero` funcs to test `TypeValidator`'s state
Configuration menu - View commit details
-
Copy full SHA for df7e2ff - Browse repository at this point
Copy the full SHA df7e2ffView commit details -
Configuration menu - View commit details
-
Copy full SHA for ffd531f - Browse repository at this point
Copy the full SHA ffd531fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 13a9a57 - Browse repository at this point
Copy the full SHA 13a9a57View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3ac1d02 - Browse repository at this point
Copy the full SHA 3ac1d02View commit details -
Configuration menu - View commit details
-
Copy full SHA for e553e7e - Browse repository at this point
Copy the full SHA e553e7eView commit details -
Add missing scheme to source fields & add missing
assert.ErrorIs
to…… `testAlwaysInvalid`
Configuration menu - View commit details
-
Copy full SHA for 8e6882b - Browse repository at this point
Copy the full SHA 8e6882bView commit details -
* rename `defaultValidators` to `defaultValidator` * replace `defaultValidators` variadic to `defaultValidator Validator` in `NewTypeValidator` func
Configuration menu - View commit details
-
Copy full SHA for fc099bf - Browse repository at this point
Copy the full SHA fc099bfView commit details