Skip to content
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: Add simple message types validators for the WRP messages #85

Merged

Conversation

denopink
Copy link
Contributor

Overview

related to #25, #78, xmidt-org/scytale#88, xmidt-org/talaria#153 and builds on top of #80 and #84 .

tl;dr

This pr introduces our wrp simple message types validators built with our validation framework introduced in #80 and leverages basic spec validators introduced in #84 . Clients can leverage these prebuilt validators to validate their messages.

Explanation

Clients can leverage our prebuilt validators to validate their messages, such as SimpleEventValidators and SimpleResponseRequestValidators:

msgv, err := NewTypeValidator(
	// Validates found msg types
	map[MessageType]Validator{
		SimpleEventMessageType:           SimpleEventValidators(),
		SimpleRequestResponseMessageType: SimpleResponseRequestValidators(),
	},
	// Validates unfound msg types
	AlwaysInvalid())
if err != nil {
	return
}

var (
	expectedStatus                  int64 = 3471
	expectedRequestDeliveryResponse int64 = 34
	expectedIncludeSpans            bool  = true
)
foundErrFailure := msgv.Validate(Message{
	Type: SimpleRequestResponseMessageType,
	// Missing scheme
	Source: "external.com",
	// Invalid Mac
	Destination:             "MAC:+++BB-44-55",
	TransactionUUID:         "DEADBEEF",
	ContentType:             "ContentType",
	Accept:                  "Accept",
	Status:                  &expectedStatus,
	RequestDeliveryResponse: &expectedRequestDeliveryResponse,
	Headers:                 []string{"Header1", "Header2"},
	Metadata:                map[string]string{"name": "value"},
	Spans: [][]string{
		// // Invalid length
		{},
		// Invalid length
		{"3"},
		// Invalid 'start time', 'duration' and 'status' components
		{"parent", "name", "not start time", "not duration", "not status"},
		// Invalid 'parent' and 'name' components
		{"1234", "1234", "1234", "1234", "1234"},
	},
	IncludeSpans: &expectedIncludeSpans,
	Path:         "/some/where/over/the/rainbow",
	Payload:      []byte{1, 2, 3, 4, 0xff, 0xce},
	ServiceName:  "ServiceName",
	// Not UFT8 URL string
	URL:        "someURL\xed\xbf\xbf.com",
	PartnerIDs: []string{"foo"},
	SessionID:  "sessionID123",
}) // Found error
foundErrSuccess1 := msgv.Validate(Message{
	Type:        SimpleRequestResponseMessageType,
	Source:      "MAC:11:22:33:44:55:66",
	Destination: "MAC:11:22:33:44:55:61",
}) // Found success
foundErrSuccess2 := msgv.Validate(Message{
	Type:   SimpleEventMessageType,
	Source: "MAC:11:22:33:44:55:66",
	// Invalid Destination
	Destination: "invalid:a-BB-44-55",
}) // Found error
unfoundErrFailure := msgv.Validate(Message{Type: CreateMessageType}) // Unfound error
fmt.Println(foundErrFailure == nil, foundErrSuccess1 == nil, foundErrSuccess2 == nil, unfoundErrFailure == nil)
// Output: false true false false
Type of Change(s)
  • Non-breaking Enhancement
  • All new and existing tests passed.

@denopink denopink added the enhancement New feature or request label Jun 15, 2022
@denopink denopink requested a review from johnabass June 15, 2022 15:18
@denopink denopink self-assigned this Jun 15, 2022
@codecov
Copy link

codecov bot commented Jun 15, 2022

Codecov Report

Merging #85 (f0c26e2) into main (1bdb169) will increase coverage by 0.80%.
The diff coverage is 47.53%.

@@            Coverage Diff             @@
##             main      #85      +/-   ##
==========================================
+ Coverage   50.16%   50.97%   +0.80%     
==========================================
  Files          21       24       +3     
  Lines        3827     3949     +122     
==========================================
+ Hits         1920     2013      +93     
- Misses       1736     1760      +24     
- Partials      171      176       +5     
Flag Coverage Δ
unittests 50.97% <47.53%> (+0.80%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
messages.go 96.77% <ø> (ø)
messages_codec.go 34.48% <20.17%> (+0.03%) ⬆️
qoslevel_string.go 40.00% <40.00%> (ø)
qos.go 100.00% <100.00%> (ø)
simpleMessageTypes_validator.go 100.00% <100.00%> (ø)
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 373d6d6...f0c26e2. Read the comment docs.

@denopink denopink requested review from mtrinh11 and renaz6 June 16, 2022 14:43
Copy link
Contributor

@mtrinh11 mtrinh11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super duper minor comments, otherwise lgtm!

* add missing comment on parent span component
* typo
simpleMessageTypes_validator.go Outdated Show resolved Hide resolved
simpleMessageTypes_validator.go Outdated Show resolved Hide resolved
simpleMessageTypes_validator.go Outdated Show resolved Hide resolved
* Add concrete error types & update existing errors (the ones affected)
* Update validator funcs to implement `ValidatorFunc` signature & update existing references
* Add new api for `Validators` & update validator factories
@denopink denopink requested a review from johnabass June 22, 2022 21:44
* add missing comment on parent span component
* typo
* Add concrete error types & update existing errors (the ones affected)
* Update validator funcs to implement `ValidatorFunc` signature & update existing references
* Add new api for `Validators` & update validator factories
.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/push.yml Outdated Show resolved Hide resolved
.github/workflows/tag.yml Outdated Show resolved Hide resolved
.sonar-project.properties Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
validator.go Outdated Show resolved Hide resolved
validator.go Outdated Show resolved Hide resolved
validator.go Outdated Show resolved Hide resolved
validator.go Outdated Show resolved Hide resolved
* Update `ValidatorError`'s `Fields` to `[]string`
* Update `NewValidatorError` to panic when both `err` and `m` are empty strings or nil
@denopink denopink requested a review from johnabass June 24, 2022 20:42
@denopink denopink merged commit dcfd4b0 into xmidt-org:main Jun 27, 2022
@denopink denopink deleted the denopink/feature/SimpleMsgTypesValidators branch July 29, 2022 19:04
@denopink denopink mentioned this pull request Aug 3, 2022
9 tasks
@denopink denopink mentioned this pull request Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants