Repository navigation
{Tests} Add CLI command request and response tests run through the engine - #1501
Draft
MaddyMicrosoft wants to merge 11 commits into
Draft
MaddyMicrosoft wants to merge 11 commits into
MaddyMicrosoft wants to merge 11 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…lidation tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ommand tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…gine Run each extension's CLI commands through the real engine with only the wire mocked, and check the request each command sends (method, URL, query, headers, body) and how it handles the response (output, paging, polling, errors). Accounts checks the calls to the profile, auth and subscription services instead. Covers KeyVault, MsGraph, Managed Identity, Resources (groups, deployments, deployment operations, rest, role assignments) and Accounts. Adds wire helpers to CommandTestHelpers (RespondTo, RespondWithHeaders, RespondToAnyUrl, RespondToAnyRequest, RespondInOrder, SentRequests, FullRequestLines, QueryValue, HeaderValues) and shared ArmUrl and EmptyList consts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ests Fix tests that could not fail or could pass for the wrong reason (Accounts cross-tenant login, KeyVault policy normalization and base64url thumbprint, Managed Identity tag merge, rest repeated headers, issued-token tenant), correct misleading Current behaviour comments, assert error codes and full paging request lines, move Accounts per-command setups out of the constructor, remove duplicate and read-only tests, and tidy naming and repeated values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… polls Set the engine's polling interval to 0 in CreateEngine so a poll without a Retry-After header does not wait the default 15 seconds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…t Location re-read Key Vault list commands must not follow a nextLink outside the selected vault's secrets and certificates endpoints, so the token is never sent elsewhere. The subscription what-if and validate read the one-shot Location result twice after a 202, which fails the command when ARM answers the second read with 404; pinned as current behaviour. Adds RespondInSequence to the wire helpers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolve CommandTestHelpers.cs by keeping this branch's explicit-type locals and response helpers; main's side differed only in using var.
This branch has not been deployed
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.
Related command
az keyvault secret *,az keyvault certificate *,az group *,az role assignment *,az deployment *,az deployment operation *,az rest,az msgraph *,az login,az logout,az account get-access-token,az profile *,az identity *,az identity federated-credential *Description
Adds tests that run CLI commands through the real engine and check what each command sends to Azure and what it does with the reply. The CLI command tests PR covers input that is rejected before anything is sent; this PR covers everything after that.
Like those tests, the real CLI parser, extension index, binder, processor and HTTP pipeline all run, and only the wire is mocked with a strict Moq mock. No recordings, credentials or files are needed. The 632 tests run in about 2 seconds.
There are two kinds of test, one file of each per command group:
*CommandRequestTests) answer with any valid reply and check what the command sent: method, URL, query string, headers and JSON body.*CommandResponseTests) send a specific reply (data, empty or multiple pages, in-progress operations, 403, 404, invalid JSON) and check what the command writes or the error it throws.For Accounts, the profile, auth and subscription services stand in for the wire: request tests check which service calls are made, and response tests check what the command writes from what they return.
What is covered:
--no-wait, failed and cancelled operations; secret value never written; 403, 404 and invalid JSON--idsbatches; generic update (--set,--add,--remove); federated credentials; pagingaz restwith all 11 parameters; role assignment$filter, scope handling, conflict returning the existing assignmentAzure-AsyncOperationandLocation; what-if result formats; tenantwait; error formattingCommandTestHelpersgains wire helpers:RespondTo,RespondWithHeaders,RespondToAnyUrl,RespondToAnyRequest,RespondInOrder,RespondInSequence,SentRequests,RequestLines,FullRequestLines,QueryValueandHeaderValues, plus sharedArmUrlandEmptyListconsts.CreateEnginesets the engine's polling interval to 0 so a long-running operation without aRetry-Afterheader doesn't wait 15 seconds between polls.Some tests pin current behaviour that looks unintended, marked with a
// Current behaviour:comment. Examples:Locationresult twice, so the command fails if ARM answers the second read with 404. The other scopes read it once. This looks like a product bug and is left for a separate fix.--tagsinto the existing tags, while group update replaces them.DateTimeOffset.nullwithout a template, while group and tenant export throw.Known gaps, left for follow-up PRs:
keyvault certificate import, a successfulkeyvault certificate download, inline--template-fileand--parameters-filedeployment bodies, and some long-running operation edge cases (failed status, several polls, 202 withoutLocation).Testing Guide
Results: 957/957 command tests (325 from the base PR plus 632 here) in Debug and Release, in about 2 s. Full
Cli.Tests: 3302 passed, 14 skipped.[Component Name]for customer-facing changes or{Component Name}for non-customer-facing changes, and does not end with trailing punctuation or spaces.