-
Notifications
You must be signed in to change notification settings - Fork 5
Add Spector test coverage for CommonPropertiesErrorClient methods #822
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
base: main
Are you sure you want to change the base?
Changes from all commits
0c735c1
9b89729
d7b7dc5
5a1bbe0
99477d1
a0cfaca
3515a36
f0ccaf9
c34b698
da3c2ae
a805eff
6fad615
10cbc55
1bece99
7863382
5195c9b
9ae8aa3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,6 +131,33 @@ export class Context { | |
| return content; | ||
| } | ||
|
|
||
| /** | ||
| * returns the impl azure_core::Error for the error type. | ||
| * if no impl is required, the empty string is returned. | ||
| * | ||
| * @param model the model for which to implement TryFrom | ||
| * @param use the use statement builder currently in scope | ||
| * @returns the impl TryFrom<T> block for type or the empty string | ||
| */ | ||
| getTryFromForError(model: rust.Model, use: Use): string { | ||
| if ((model.flags & rust.ModelFlags.Error) === 0) { | ||
| return ''; | ||
| } | ||
|
|
||
| use.add('azure_core::error', 'ErrorKind'); | ||
| const indent = new helpers.indentation(); | ||
| let content = `impl TryFrom<azure_core::Error> for ${helpers.getTypeDeclaration(model)} {\n`; | ||
| 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())?),`; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| content += `${indent.get()}_ => Err(azure_core::Error::with_message(azure_core::error::ErrorKind::DataConversion, "ErrorKind was not HttpResponse and could not be parsed."))`; | ||
| content += `${indent.pop().get()}}\n`; | ||
| content += `${indent.pop().get()}}\n`; | ||
| content += '}\n\n'; | ||
| return content; | ||
| } | ||
|
|
||
| /** | ||
| * returns the body format for the provided model | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ export interface RustEmitterOptions { | |
| 'overwrite-lib-rs': boolean; | ||
| /** Whether to omit documentation links in generated code. Defaults to false */ | ||
| 'temp-omit-doc-links': boolean; | ||
| /** Whether to emit error types */ | ||
| 'emit-error-types': boolean; | ||
| } | ||
|
|
||
| const EmitterOptionsSchema: JSONSchemaType<RustEmitterOptions> = { | ||
|
|
@@ -59,6 +61,12 @@ const EmitterOptionsSchema: JSONSchemaType<RustEmitterOptions> = { | |
| default: false, | ||
| description: 'Whether to omit documentation links in generated code. Defaults to false' | ||
| }, | ||
| 'emit-error-types': { | ||
| type: 'boolean', | ||
| nullable: false, | ||
| default: false, | ||
| description: 'Whether to emit error types. Defaults to false' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should always emit error models. Why not? |
||
| }, | ||
| }, | ||
| required: [ | ||
| 'crate-name', | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| use azure_core::credentials::{AccessToken, TokenCredential, TokenRequestOptions}; | ||
| use azure_core::time::OffsetDateTime; | ||
| use azure_core::Result; | ||
| use spector_armcommon::CommonPropertiesClient; | ||
| use std::sync::Arc; | ||
|
|
||
| #[derive(Debug)] | ||
| struct FakeTokenCredential { | ||
| pub token: String, | ||
| } | ||
|
|
||
| impl FakeTokenCredential { | ||
| pub fn new(token: String) -> Self { | ||
| FakeTokenCredential { token } | ||
| } | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl TokenCredential for FakeTokenCredential { | ||
| async fn get_token( | ||
| &self, | ||
| _scopes: &[&str], | ||
| _options: Option<TokenRequestOptions<'_>>, | ||
| ) -> Result<AccessToken> { | ||
| Ok(AccessToken::new( | ||
| self.token.clone(), | ||
| OffsetDateTime::now_utc(), | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| pub fn create_client() -> CommonPropertiesClient { | ||
| CommonPropertiesClient::new( | ||
| "http://localhost:3000", | ||
| Arc::new(FakeTokenCredential::new("fake_token".to_string())), | ||
| "00000000-0000-0000-0000-000000000000".to_string(), | ||
| None, | ||
| ) | ||
| .unwrap() | ||
| } |
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.
You can also set per-project additional args inline.