test: Update getRegionsWithCaps function to also accept a list of plans that must be available in the identified region#555
Merged
ykim-akamai merged 4 commits intolinode:mainfrom Jul 19, 2024
Conversation
| } | ||
|
|
||
| // Function to check if a region has the required plans available | ||
| regionHasPlans := func(regionID string) bool { |
Contributor
There was a problem hiding this comment.
Nice use of closures!
| Returns: | ||
| - string values representing the IDs of regions that meet the given criteria. | ||
| */ | ||
| func getRegionsWithCaps(t *testing.T, client *linodego.Client, capabilities, plans []string) []string { |
Contributor
There was a problem hiding this comment.
optional: We can considerably reduce the number of iterations we need to run by aggregating all availabilities into a map hashing on (region, plan):
regionsAvailabilities, err := client.ListRegionsAvailability(context.Background(), nil)
require.NoError(t, err)
type availKey struct {
Region string
Plan string
}
availMap := make(map[availKey]linodego.RegionAvailability, len(regionsAvailabilities))
for _, avail := range regionsAvailabilities {
availMap[availKey{Region: avail.Region, Plan: avail.Plan}] = avail
}
// ...
regionHasPlans := func(regionID string) bool {
for _, plan := range plans {
if avail, ok := availMap[availKey{Region: regionID, Plan: plan}]; !ok || !avail.Available {
return false
}
}
return true
}Since this is just for tests I don't think it's a big deal either way; just thought I'd share another approach 👍
Contributor
Author
There was a problem hiding this comment.
This is a great suggestion! I didn't think of putting it into a hash map but this will for sure be faster than my previous solution 🚀
yec-akamai
approved these changes
Jul 19, 2024
Contributor
yec-akamai
left a comment
There was a problem hiding this comment.
Tests works well locally, nice work!
ykim-akamai
commented
Jul 19, 2024
|
|
||
| // Function to check if a region has the required plans available | ||
| regionHasPlans := func(regionID string) bool { | ||
| if len(plans) == 0 { |
Contributor
Author
There was a problem hiding this comment.
Still left this check in to avoid any unnecessary map lookups when there are no plans to check.
lgarber-akamai
approved these changes
Jul 19, 2024
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📝 Description
A helper function has been updated for the logic to resolve integration test regions that also accepts a list of plans which must be available in the resolved region
Note: the function takes list value of plans as an optional parameter
✔️ How to Test
make testint📷 Preview
If applicable, include a screenshot or code snippet of this change. Otherwise, please remove this section.