-
Notifications
You must be signed in to change notification settings - Fork 4
feat: retrieve struct validation #57
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
Open
TommoLeedsy
wants to merge
20
commits into
main
Choose a base branch
from
feat/retrieve-struct-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
544c5d7
feat: retrieve struct validation for go validator tags using validjso…
TommoLeedsy 3e34dc2
chore: go mod tidy
TommoLeedsy 439c8a4
fix: remove ValidationTags tests as these are handled in a sperate pa…
TommoLeedsy 092390f
chore: reformat
TommoLeedsy 3618793
chore: handle mergo error
TommoLeedsy 1044c45
chore: remove debuging print
TommoLeedsy bd4635e
chore: update schema
TommoLeedsy 5f2b6c6
chore: fix comment
TommoLeedsy 42905bb
chore: add docstrings
TommoLeedsy cbf1d44
fix: test broke due to changing types
TommoLeedsy 48c3a9d
Merge branch 'main' into feat/retrieve-struct-validation
TommoLeedsy 8d24c8c
chore: fix test broken in merge
TommoLeedsy e733b7e
chore: rename integration tests package names
TommoLeedsy 320060c
chore: updated astra features
TommoLeedsy 880e807
chore: improve validation exmples
TommoLeedsy fc5b971
chore: add integration test
TommoLeedsy aee3759
fix: improve handling of dive tag
TommoLeedsy ddf854e
Merge branch 'main' into feat/retrieve-struct-validation
TommoLeedsy a91141c
chore: update snapshot test
TommoLeedsy f797703
Merge branch 'main' into feat/retrieve-struct-validation
TommoLeedsy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,118 +1,99 @@ | ||
| package astTraversal | ||
|
|
||
| import ( | ||
| "go/types" | ||
| "reflect" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestParseStructTag(t *testing.T) { | ||
| testCases := []struct { | ||
| field string | ||
| tag string | ||
| expectedBindingTags BindingTagMap | ||
| expectedValidationTags ValidationTagMap | ||
| field string | ||
| tag string | ||
| node types.Type | ||
| expectedBindingTags BindingTagMap | ||
| }{ | ||
| { | ||
| field: "Field1", | ||
| tag: `json:"field1"`, | ||
| node: &types.Basic{}, | ||
| expectedBindingTags: BindingTagMap{ | ||
| JSONBindingTag: { | ||
| Name: "field1", | ||
| NotShown: false, | ||
| ReturnOptional: false, | ||
| }, | ||
| }, | ||
| expectedValidationTags: ValidationTagMap{}, | ||
| }, | ||
| { | ||
| field: "Field2", | ||
| tag: `json:"field2,omitempty"`, | ||
| node: &types.Basic{}, | ||
| expectedBindingTags: BindingTagMap{ | ||
| JSONBindingTag: { | ||
| Name: "field2", | ||
| NotShown: false, | ||
| ReturnOptional: true, | ||
| }, | ||
| }, | ||
| expectedValidationTags: ValidationTagMap{}, | ||
| }, | ||
| { | ||
| field: "Field3", | ||
| tag: `json:""`, | ||
| node: &types.Basic{}, | ||
| expectedBindingTags: BindingTagMap{ | ||
| JSONBindingTag: { | ||
| Name: "Field3", | ||
| NotShown: false, | ||
| ReturnOptional: false, | ||
| }, | ||
| }, | ||
| expectedValidationTags: ValidationTagMap{}, | ||
| }, | ||
| { | ||
| field: "Field4", | ||
| tag: `json:",omitempty"`, | ||
| node: &types.Basic{}, | ||
| expectedBindingTags: BindingTagMap{ | ||
| JSONBindingTag: { | ||
| Name: "Field4", | ||
| NotShown: false, | ||
| ReturnOptional: true, | ||
| }, | ||
| }, | ||
| expectedValidationTags: ValidationTagMap{}, | ||
| }, | ||
| { | ||
| field: "Field5", | ||
| tag: `json:"-"`, | ||
| node: &types.Basic{}, | ||
| expectedBindingTags: BindingTagMap{ | ||
| JSONBindingTag: { | ||
| Name: "", | ||
| NotShown: true, | ||
| ReturnOptional: false, | ||
| }, | ||
| }, | ||
| expectedValidationTags: ValidationTagMap{}, | ||
| }, | ||
| { | ||
| field: "Field6", | ||
| tag: `validate:"required"`, | ||
| expectedBindingTags: BindingTagMap{ | ||
| NoBindingTag: { | ||
| Name: "Field6", | ||
| NotShown: false, | ||
| ReturnOptional: false, | ||
| }, | ||
| }, | ||
| expectedValidationTags: ValidationTagMap{ | ||
| ValidatorValidationTag: { | ||
| IsRequired: true, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| field: "Field7", | ||
| tag: ``, | ||
| node: &types.Basic{}, | ||
| expectedBindingTags: BindingTagMap{ | ||
| NoBindingTag: { | ||
| Name: "Field7", | ||
| NotShown: false, | ||
| ReturnOptional: false, | ||
| }, | ||
| }, | ||
| expectedValidationTags: ValidationTagMap{}, | ||
| }, | ||
| } | ||
|
|
||
| for _, testCase := range testCases { | ||
| t.Run("field="+testCase.field, func(t *testing.T) { | ||
| bindingTags, validationTags := ParseStructTag(testCase.field, testCase.tag) | ||
| bindingTags, _, _ := ParseStructTag(testCase.field, testCase.node, testCase.tag) | ||
|
|
||
| if !reflect.DeepEqual(bindingTags, testCase.expectedBindingTags) { | ||
| t.Errorf("Expected BindingTags: %v, but got: %v", testCase.expectedBindingTags, bindingTags) | ||
| } | ||
|
|
||
| if !reflect.DeepEqual(validationTags, testCase.expectedValidationTags) { | ||
| t.Errorf("Expected ValidationTags: %v, but got: %v", testCase.expectedValidationTags, validationTags) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.