-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add json schema conditional validations #65
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b0f6068
feat: add json schema conditional validations
ishanarya0 eb019ed
test: add JSONSchema tests
ishanarya0 1e638e7
fix: linting issues
ishanarya0 8d3bbfb
fix: remove unnecessary imports
ishanarya0 edb9972
fix(kubernetes): add check for host field for URI format and http/s p…
rohilsurana 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| package kubernetes | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/xeipuuv/gojsonschema" | ||
| ) | ||
|
|
||
| func TestModule_KubernetesJSONSchema(t *testing.T) { | ||
| tests := []struct { | ||
| Case string | ||
| wantErr error | ||
| want bool | ||
| }{ | ||
| { | ||
| Case: `{ | ||
| "host": "http://0.0.0.0:1234", | ||
| "insecure": true, | ||
| "token": "token" | ||
| }`, | ||
| wantErr: nil, | ||
| want: true, | ||
| }, | ||
| { | ||
| Case: `{ | ||
| "host": "http://0.0.0.0:1234", | ||
| "insecure": false, | ||
| "token": "token" | ||
| }`, | ||
| wantErr: nil, | ||
| want: false, | ||
| }, | ||
| { | ||
| Case: `{ | ||
| "host": "http://0.0.0.0:1234", | ||
| "insecure": false, | ||
| "cluster_ca_certificate": "c_ca_cert", | ||
| "token": "token" | ||
| }`, | ||
| wantErr: nil, | ||
| want: true, | ||
| }, | ||
| { | ||
| Case: `{ | ||
| "host": "http://0.0.0.0:1234", | ||
| "cluster_ca_certificate": "c_ca_cert", | ||
| "token": "token" | ||
| }`, | ||
| wantErr: nil, | ||
| want: true, | ||
| }, | ||
| { | ||
| Case: `{ | ||
| "host": "http://0.0.0.0:1234", | ||
| "insecure": true, | ||
| "client_key": "c_key", | ||
| "client_certificate": "c_cert" | ||
| }`, | ||
| wantErr: nil, | ||
| want: true, | ||
| }, | ||
| { | ||
| Case: ` "host": "http://0.0.0.0:1234", | ||
| "insecure": true, | ||
| "client_key": "c_key" | ||
| }`, | ||
| wantErr: nil, | ||
| want: false, | ||
| }, | ||
| { | ||
| Case: `{ | ||
| "host": "http://0.0.0.0:1234", | ||
| "insecure": true, | ||
| "token": "token", | ||
| "client_key": "c_key", | ||
| "client_certificate": "c_cert" | ||
| }`, | ||
| wantErr: nil, | ||
| want: false, | ||
| }, | ||
| { | ||
| Case: `{ | ||
| "host": "http://0.0.0.0:1234", | ||
| "insecure": true, | ||
| "token": "token", | ||
| "client_key": "c_key" | ||
| }`, | ||
| wantErr: nil, | ||
| want: true, | ||
| }, | ||
| } | ||
| loader := gojsonschema.NewStringLoader(configSchema) | ||
| schema, _ := gojsonschema.NewSchema(loader) | ||
|
|
||
| for _, tt := range tests { | ||
| tt := tt | ||
| t.Run(tt.Case, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| c := gojsonschema.NewStringLoader(tt.Case) | ||
| result, err := schema.Validate(c) | ||
| if tt.wantErr != nil { | ||
| assert.Error(t, err) | ||
| assert.True(t, errors.Is(err, tt.wantErr)) | ||
| } else { | ||
| assert.NoError(t, err) | ||
| } | ||
| assert.Equal(t, tt.want, result.Valid()) | ||
| }) | ||
| } | ||
| } |
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.