-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add tests for plane-scoped API scenarios #5620
Conversation
Part of: #5609 This change includes tests for the "plane-scoped" list API scenarios. The existing code in the list shared operation mostly already works for this scenario, but we need to toggle the query to be recursive. We don't do this by default because it would be incorrect and slow. Also updated some of the cosmosdb storage tests to better cover this scenario. Everything was working as expected, but the tests themselves weren't actually covering this scenario.
Radius functional test overview
Click here to see the list of tools in the current test run
Test Status⌛ Building Radius and pushing container images for functional tests... |
ResourceType: serviceCtx.ResourceID.Type(), | ||
RootScope: serviceCtx.ResourceID.RootScope(), | ||
ResourceType: serviceCtx.ResourceID.Type(), | ||
ScopeRecursive: e.RecursiveQuery, |
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.
We need to have different behaviors for this controller between the plane-scope and resource-group-scope usecases. Basically any time there's a mismatch of the query scope and the resource scope we need recursive.
This seemed like a reasonable way to toggle the behavior, open to suggestions.
{"list-envs-more-items-than-top", resourceTestHeaderFile, 10, 5, "5", true, false}, | ||
{"list-envs-less-items-than-top", resourceTestHeaderFile, 5, 5, "10", false, false}, | ||
{"list-envs-no-top", resourceTestHeaderFile, 5, 5, "", false, false}, | ||
{"list-envs-plane-scope-more-items-than-top", "resource_planescope_requestheaders.json", 5, 5, "", false, false}, |
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.
We didn't have a test for this case, so I added one.
"Accept-Language": "en-US", | ||
"Content-Length": "305", | ||
"Content-Type": "application/json; charset=utf-8", | ||
"Referer": "https://radius.dev/planes/radius/local/providers/applications.core/environments/env0?api-version=2022-03-15-privatepreview", |
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.
Needed another test file, because we need the root scope to be different. This is actually kinda wierd, but it matches what the exisiting test is doing (getting a URL for a resource get, but testing for list).
rootScope: "/planes/radius/local", | ||
resourceType: "", | ||
filters: []store.QueryFilter{}, | ||
expected: 3, |
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.
Looking for input on this, I think the existing tests were just wrong. They were only covering the subscription ID case.
Test Results2 748 tests +3 2 741 ✔️ +3 1m 58s ⏱️ ±0s Results for commit f323dff. ± Comparison against base commit 4d124b3. This pull request removes 2 and adds 5 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
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.
LGTM.
@@ -503,40 +526,40 @@ func TestQuery(t *testing.T) { | |||
}) | |||
} | |||
|
|||
// Query with subscriptionID | |||
// Query with subscriptionID or plane - These are recursive queries |
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.
This test will be skipped unless we set the following envvars.
If you didn't validate it, it is fine.
I will do it when I migrate 3rd-party cosmosdb to the official cosmosdb lib. (SDK team finally announced the official cosmosdb lib :) )
https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/data/azcosmos
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 did validate it. I create a cosmos DB and ran the tests
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 did validate it. I create a cosmos DB and ran the tests
Thanks! :) I may use cosmosdb simulator when I migrate to the official sdk.
Radius functional test overview
Click here to see the list of tools in the current test run
Test Status⌛ Building Radius and pushing container images for functional tests... |
// RecursiveQuery specifies whether the store query should be recursive or not. This should be set when the | ||
// scope of the list operation does not match the scope of the underlying resource type. | ||
RecursiveQuery bool |
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.
Do we need this or can we understand this from the request?
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.
We need this right now. Let me explain what do and do not know from the request.
- We know the scope of the query - that's the part of the URL path before
providers
- We know the resource type - that's the part of the URL path immediately after
providers
- We do not know the scope of the resource being queried - this is the info we need to decide if the query is recursive.
Description
This change includes tests for the "plane-scoped" list API scenarios. The existing code in the list shared operation mostly already works for this scenario, but we need to toggle the query to be recursive. We don't do this by default because it would be incorrect and slow.
Also updated some of the cosmosdb storage tests to better cover this scenario. Everything was working as expected, but the tests themselves weren't actually covering this scenario.
Issue reference
Part of: radius-project/core-team#1197
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list:
Auto-generated summary
🤖 Generated by Copilot at 687d5d6
Summary
📄🧪🔎
This pull request adds support for plane-scoped queries in the
armrpc
frontend and thecosmosdb
store, and improves the test coverage and specificity for theListResources
operation. It modifies the query construction logic and the request headers in thedefaultoperation
package, and adds new test cases and test data files.Walkthrough
RecursiveQuery
field toListResources
struct and initialize it to false inNewListResources
function (link,link)ScopeRecursive
field of store query toRecursiveQuery
field ofListResources
instance inRun
method (link)v1
package inlistresources_test.go
file (link)headerFile
field tolistEnvsCases
slice and a new test case for plane-scoped list operation inTestListResourcesRun
function (link)ARMRequestContext
from context and addexpectedQuery
variable to each test case inTestListResourcesRun
function (link,link)RecursiveQuery
field ofListResources
instance toplaneScope
field of test case inTestListResourcesRun
function (link)resource_planescope_requestheaders.json
file totestdata
folder with request headers for plane-scoped list operation test case (link)TestConstructCosmosDBQuery
function (link,link)TestQuery
function to include plane-scoped query scenarios (link)subscriptionID
field torootScope
and modify its values to include plane scope insubscriptionIDCases
map inTestQuery
function (link,link,link)subscriptionIDCases
map inTestQuery
function (link,link)rootScope
field instead ofsubscriptionID
field inTestQuery
function (link)rootScope
inTestQuery
function (link)