Skip to content

Add Spector test coverage for CommonPropertiesErrorClient methods#822

Open
Copilot wants to merge 17 commits intomainfrom
copilot/add-spector-test-coverage
Open

Add Spector test coverage for CommonPropertiesErrorClient methods#822
Copilot wants to merge 17 commits intomainfrom
copilot/add-spector-test-coverage

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

Adds missing test coverage for create_for_user_defined_error() and get_for_predefined_error() methods in CommonPropertiesErrorClient.

Changes

  • New test file: common_properties_error_client_test.rs under packages/typespec-rust/test/spector/azure/resource-manager/common-properties/tests/
    • Tests use ConfidentialResource model and validate error response http code
    • Follows existing test patterns from common_properties_managed_identity_client_test.rs (FakeTokenCredential, helper functions, assertion structure)
    • Designed to run with Spector mock server on localhost:3000

No modifications to generated source code or emitter.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add Spector test coverage for the CommonPropertiesErrorClient's methods</issue_title>
<issue_description>1. Do not modify the generated rust source code (in src/generated), only modify the emitter code (in /packages/typespec-rust/src/) if necessary
2. The test for the common-properties does already exist (under packages/typespec-rust/test/spector/azure/resource-manager/common-properties/tests/). Add a file called common_properties_error_client_test.rs there, and add tests for two methods - create_for_user_defined_error() and get_for_predefined_error().</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 3, 2026 11:00
…user_defined_error and get_for_predefined_error

Co-authored-by: antkmsft <41349689+antkmsft@users.noreply.github.com>
Co-authored-by: antkmsft <41349689+antkmsft@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Spector test coverage for CommonPropertiesErrorClient methods Add Spector test coverage for CommonPropertiesErrorClient methods Feb 3, 2026
Copilot AI requested a review from antkmsft February 3, 2026 11:12
@antkmsft antkmsft marked this pull request as ready for review February 12, 2026 00:35
Copilot AI review requested due to automatic review settings February 12, 2026 00:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Spector integration tests for the CommonPropertiesErrorClient operations in the common-properties ARM test crate, exercising the error paths for two previously untested client methods.

Changes:

  • Adds a new integration test file covering create_for_user_defined_error() and get_for_predefined_error().
  • Verifies the returned azure_core::Error has the expected HTTP status codes (400/404).

}
}

const tspConfigPath = `${outputDir}/tspconfig.yaml`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also set per-project additional args inline.

'spector_armcommon': {input: 'azure/resource-manager/common-properties', args: ['emit-error-types=true']},

content += `${indent.get()}type Error = azure_core::Error;\n`;
content += `${indent.get()}fn try_from(error: azure_core::Error) -> std::result::Result<Self, Self::Error> {\n`;
content += `${indent.push().get()}match error.kind() {`
content += `${indent.push().get()}ErrorKind::HttpResponse { raw_response: Some(raw_response), .. } => Ok(serde_json::from_str(raw_response.body().clone().into_string()?.as_ref())?),`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Don't call serde_json directly. You can use raw_response.body().json()? even, or call azure_core::json directly, but...
  2. Why are you assuming JSON? Shouldn't this take into account the format the client actually uses, same as how the F: Format is determined for Response<T, F>?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're also needless cloning the body. Deserializing just needs a reference. See https://azure.github.io/azure-sdk/rust_implementation.html for an example of a TryFrom for an error.

type: 'boolean',
nullable: false,
default: false,
description: 'Whether to emit error types. Defaults to false'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should always emit error models. Why not? TryFrom should be optional. In fact, we need it to be because what if they also want to take headers into account like Storage does? They'd need to implement TryFrom themselves.

"async-trait",
"azure_core",
"serde",
"serde_json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed because you shouldn't be calling into serde_json directly anyway, nor even assuming JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Spector test coverage for the CommonPropertiesErrorClient's methods

5 participants