-
Notifications
You must be signed in to change notification settings - Fork 36
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
feat: handle url limit in rest #3186
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ffcc1f
feat: handle url limit in rest
Hardikl 3becf39
Merge remote-tracking branch 'origin/main' into hl_rest_limit
Hardikl bed7d26
feat: handled review comments
Hardikl a56e473
Merge remote-tracking branch 'origin/main' into hl_rest_limit
Hardikl 650d03b
feat: handled review comments
Hardikl 5e36765
feat: handled review comments
Hardikl 5ed6e97
feat: handled review comments
Hardikl 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 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 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 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 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,100 @@ | ||
package rest | ||
|
||
import ( | ||
"github.com/google/go-cmp/cmp" | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
func TestBuild(t *testing.T) { | ||
testQuery := "storage/volumes" | ||
testFields := []string{"name", "svm"} | ||
testHiddenFields := []string{"statistics"} | ||
testFilter := []string{""} | ||
testReturnTimeout := 10 | ||
expectedHrefTest1 := "api/storage/volumes?return_records=true&fields=name,statistics,svm&return_timeout=10&ignore_unknown_fields=true" | ||
hrefTest1 := NewHrefBuilder(). | ||
APIPath(testQuery). | ||
Fields(testFields). | ||
HiddenFields(testHiddenFields). | ||
Filter(testFilter). | ||
ReturnTimeout(&testReturnTimeout). | ||
IsIgnoreUnknownFieldsEnabled(true). | ||
Build() | ||
|
||
if hrefTest1 != expectedHrefTest1 { | ||
t.Errorf("hrefTest1 should be %s but got %s", expectedHrefTest1, hrefTest1) | ||
} | ||
|
||
testFields = make([]string, 0) | ||
for i := range URLMaxLimit / len("Test") { | ||
testFields = append(testFields, "Test"+strconv.Itoa(i)) | ||
} | ||
|
||
expectedHrefTest2 := "api/storage/volumes?return_records=true&fields=*,statistics&return_timeout=10&ignore_unknown_fields=true" | ||
hrefTest2 := NewHrefBuilder(). | ||
APIPath(testQuery). | ||
Fields(testFields). | ||
HiddenFields(testHiddenFields). | ||
Filter(testFilter). | ||
ReturnTimeout(&testReturnTimeout). | ||
IsIgnoreUnknownFieldsEnabled(true). | ||
Build() | ||
|
||
if hrefTest2 != expectedHrefTest2 { | ||
t.Errorf("hrefTest2 should be %s but got %s", expectedHrefTest2, hrefTest2) | ||
} | ||
} | ||
|
||
func TestFields(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
fields []string | ||
hiddenFields []string | ||
expectedResult []string | ||
}{ | ||
{ | ||
name: "Test with fields and no hidden fields", | ||
fields: []string{ | ||
"uuid", | ||
"block_storage.primary.disk_type", | ||
"block_storage.primary.raid_type", | ||
}, | ||
expectedResult: []string{ | ||
"block_storage.primary.disk_type", | ||
"block_storage.primary.raid_type", | ||
"uuid", | ||
}, | ||
}, | ||
{ | ||
name: "Test with fields and hidden fields", | ||
fields: []string{ | ||
"uuid", | ||
"block_storage.primary.disk_type", | ||
"block_storage.primary.raid_type", | ||
}, | ||
hiddenFields: []string{ | ||
"hidden_field1", | ||
"hidden_field2", | ||
}, | ||
expectedResult: []string{ | ||
"block_storage.primary.disk_type", | ||
"block_storage.primary.raid_type", | ||
"hidden_field1", | ||
"hidden_field2", | ||
"uuid", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
hBuilder := NewHrefBuilder() | ||
hBuilder.Fields(tt.fields).HiddenFields(tt.hiddenFields).Build() | ||
diff := cmp.Diff(hBuilder.fields, tt.expectedResult) | ||
if diff != "" { | ||
t.Errorf("Mismatch (-got +want):\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If hidden fields are added below the URLMaxLimit check, they may cause the URL to exceed the max. Hidden fields need to be part of the max check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that, if hiddenFields would be prior then if it exceed the limit, then it will pass
*
and no hidden fields would be coming in that response.But yeah, if it was in later then url rest limit 414 error will come and whole rest call would be failed.