-
Notifications
You must be signed in to change notification settings - Fork 80
Add coverage cases for arrays-item-types in cadl-ranch #2103
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
Changes from all commits
654367b
efdbd9d
96755ff
4c0d1b6
bb2ba11
ffcc449
a5065ab
cdc6376
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 |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import { assert } from "chai"; | ||
| import { ArrayClient } from "./generated/arrays/items/src/index.js"; | ||
|
|
||
| interface TypeDetail { | ||
| type: string; | ||
| defaultValue: any; | ||
| convertedToFn?: (_: any) => any; | ||
| } | ||
|
|
||
| const testedTypes: TypeDetail[] = [ | ||
| { | ||
| type: "int32", | ||
| defaultValue: [1, 2] | ||
| }, | ||
| { | ||
| type: "int64", | ||
| defaultValue: [Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER] | ||
| }, | ||
| { | ||
| type: "boolean", | ||
| defaultValue: [true, false] | ||
| }, | ||
| { | ||
| type: "string", | ||
| defaultValue: ["hello", ""] | ||
| }, | ||
| { | ||
| type: "float32", | ||
| defaultValue: [42.42] | ||
| }, | ||
| { | ||
| type: "datetime", | ||
| defaultValue: [new Date("2022-08-26T18:38:00Z")] | ||
|
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. Datetime type is a Date typescript type in modular. |
||
| }, | ||
| { | ||
| type: "duration", | ||
| defaultValue: ["P123DT22H14M12.011S"] | ||
| }, | ||
| { | ||
| type: "unknown", | ||
| defaultValue: [1, "hello", null] | ||
| }, | ||
| { | ||
| type: "model", | ||
| defaultValue: [ | ||
| { property: "hello", children: undefined }, | ||
| { property: "world", children: undefined } | ||
|
Comment on lines
+46
to
+47
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. the children: undefined are added by the current serialization and deserialization logic in modular. |
||
| ] | ||
| }, | ||
| { | ||
| type: "nullable-float", | ||
| defaultValue: [1.2, null, 3.0] | ||
| } | ||
| ]; | ||
| describe("Array Item-Types Client", () => { | ||
| let client: ArrayClient; | ||
|
|
||
| beforeEach(() => { | ||
| client = new ArrayClient({ | ||
| allowInsecureConnection: true, | ||
| retryOptions: { | ||
| maxRetries: 0 | ||
| } | ||
| }); | ||
| }); | ||
| for (let item of testedTypes) { | ||
| it(`should get ${item.type} value`, async () => { | ||
| try { | ||
| let result: any; | ||
| switch (item.type) { | ||
| case "int32": | ||
| result = await client.int32Value.get(); | ||
| break; | ||
| case "int64": | ||
| result = await client.int64Value.get(); | ||
| break; | ||
| case "boolean": | ||
| result = await client.booleanValue.get(); | ||
| break; | ||
| case "string": | ||
| result = await client.stringValue.get(); | ||
| break; | ||
| case "float32": | ||
| result = await client.float32Value.get(); | ||
| break; | ||
| case "datetime": | ||
| result = await client.datetimeValue.get(); | ||
| break; | ||
| case "duration": | ||
| result = await client.durationValue.get(); | ||
| break; | ||
| case "unknown": | ||
| result = await client.unknownValue.get(); | ||
| break; | ||
| case "model": | ||
| result = await client.modelValue.get(); | ||
| break; | ||
| case "nullable-float": | ||
| result = await client.nullableFloatValue.get(); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| assert.deepEqual(result, item.defaultValue); | ||
| } catch (err) { | ||
| assert.fail(err as string); | ||
| } | ||
| }); | ||
| } | ||
| for (let item of testedTypes) { | ||
| it(`should put ${item.type} vaule`, async () => { | ||
| try { | ||
| let result: any; | ||
| switch (item.type) { | ||
| case "int32": | ||
| result = await client.int32Value.put(item.defaultValue); | ||
| break; | ||
| case "int64": | ||
| result = await client.int64Value.put(item.defaultValue); | ||
| break; | ||
| case "boolean": | ||
| result = await client.booleanValue.put(item.defaultValue); | ||
| break; | ||
| case "string": | ||
| result = await client.stringValue.put(item.defaultValue); | ||
| break; | ||
| case "float32": | ||
| result = await client.float32Value.put(item.defaultValue); | ||
| break; | ||
| case "datetime": | ||
| result = await client.datetimeValue.put(item.defaultValue); | ||
| break; | ||
| case "duration": | ||
| result = await client.durationValue.put(item.defaultValue); | ||
| break; | ||
| case "unknown": | ||
| result = await client.unknownValue.put(item.defaultValue); | ||
| break; | ||
| case "model": | ||
| result = await client.modelValue.put(item.defaultValue); | ||
| break; | ||
| case "nullable-float": | ||
| result = await client.nullableFloatValue.put(item.defaultValue); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| assert.isUndefined(result); | ||
| } catch (err) { | ||
| assert.fail(err as string); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import { Pipeline } from "@azure/core-rest-pipeline"; | ||
| import { | ||
| getInt32ValueOperations, | ||
| Int32ValueOperations, | ||
| } from "./classic/int32Value/index.js"; | ||
| import { | ||
| getInt64ValueOperations, | ||
| Int64ValueOperations, | ||
| } from "./classic/int64Value/index.js"; | ||
| import { | ||
| getBooleanValueOperations, | ||
| BooleanValueOperations, | ||
| } from "./classic/booleanValue/index.js"; | ||
| import { | ||
| getStringValueOperations, | ||
| StringValueOperations, | ||
| } from "./classic/stringValue/index.js"; | ||
| import { | ||
| getFloat32ValueOperations, | ||
| Float32ValueOperations, | ||
| } from "./classic/float32Value/index.js"; | ||
| import { | ||
| getDatetimeValueOperations, | ||
| DatetimeValueOperations, | ||
| } from "./classic/datetimeValue/index.js"; | ||
| import { | ||
| getDurationValueOperations, | ||
| DurationValueOperations, | ||
| } from "./classic/durationValue/index.js"; | ||
| import { | ||
| getUnknownValueOperations, | ||
| UnknownValueOperations, | ||
| } from "./classic/unknownValue/index.js"; | ||
| import { | ||
| getModelValueOperations, | ||
| ModelValueOperations, | ||
| } from "./classic/modelValue/index.js"; | ||
| import { | ||
| getNullableFloatValueOperations, | ||
| NullableFloatValueOperations, | ||
| } from "./classic/nullableFloatValue/index.js"; | ||
| import { createArray, ArrayClientOptions, ArrayContext } from "./api/index.js"; | ||
|
|
||
| export { ArrayClientOptions } from "./api/ArrayContext.js"; | ||
|
|
||
| export class ArrayClient { | ||
| private _client: ArrayContext; | ||
| /** The pipeline used by this client to make requests */ | ||
| public readonly pipeline: Pipeline; | ||
|
|
||
| /** Illustrates various of dictionaries. */ | ||
| constructor(options: ArrayClientOptions = {}) { | ||
| this._client = createArray(options); | ||
| this.pipeline = this._client.pipeline; | ||
| this.int32Value = getInt32ValueOperations(this._client); | ||
| this.int64Value = getInt64ValueOperations(this._client); | ||
| this.booleanValue = getBooleanValueOperations(this._client); | ||
| this.stringValue = getStringValueOperations(this._client); | ||
| this.float32Value = getFloat32ValueOperations(this._client); | ||
| this.datetimeValue = getDatetimeValueOperations(this._client); | ||
| this.durationValue = getDurationValueOperations(this._client); | ||
| this.unknownValue = getUnknownValueOperations(this._client); | ||
| this.modelValue = getModelValueOperations(this._client); | ||
| this.nullableFloatValue = getNullableFloatValueOperations(this._client); | ||
| } | ||
|
|
||
| /** The operation groups for Int32Value */ | ||
| public readonly int32Value: Int32ValueOperations; | ||
| /** The operation groups for Int64Value */ | ||
| public readonly int64Value: Int64ValueOperations; | ||
| /** The operation groups for BooleanValue */ | ||
| public readonly booleanValue: BooleanValueOperations; | ||
| /** The operation groups for StringValue */ | ||
| public readonly stringValue: StringValueOperations; | ||
| /** The operation groups for Float32Value */ | ||
| public readonly float32Value: Float32ValueOperations; | ||
| /** The operation groups for DatetimeValue */ | ||
| public readonly datetimeValue: DatetimeValueOperations; | ||
| /** The operation groups for DurationValue */ | ||
| public readonly durationValue: DurationValueOperations; | ||
| /** The operation groups for UnknownValue */ | ||
| public readonly unknownValue: UnknownValueOperations; | ||
| /** The operation groups for ModelValue */ | ||
| public readonly modelValue: ModelValueOperations; | ||
| /** The operation groups for NullableFloatValue */ | ||
| public readonly nullableFloatValue: NullableFloatValueOperations; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import { ClientOptions } from "@azure-rest/core-client"; | ||
| import { ArrayContext } from "../rest/index.js"; | ||
| import getClient from "../rest/index.js"; | ||
|
|
||
| export interface ArrayClientOptions extends ClientOptions {} | ||
|
|
||
| export { ArrayContext } from "../rest/index.js"; | ||
|
|
||
| /** Illustrates various of dictionaries. */ | ||
| export function createArray(options: ArrayClientOptions = {}): ArrayContext { | ||
| const clientContext = getClient(options); | ||
| return clientContext; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import { | ||
| ArrayContext as Client, | ||
| BooleanValueGet200Response, | ||
| BooleanValuePut204Response, | ||
| } from "../../rest/index.js"; | ||
| import { | ||
| StreamableMethod, | ||
| operationOptionsToRequestParameters, | ||
| createRestError, | ||
| } from "@azure-rest/core-client"; | ||
| import { | ||
| BooleanValueGetOptions, | ||
| BooleanValuePutOptions, | ||
| } from "../../models/options.js"; | ||
|
|
||
| export function _booleanValueGetSend( | ||
| context: Client, | ||
| options: BooleanValueGetOptions = { requestOptions: {} }, | ||
| ): StreamableMethod<BooleanValueGet200Response> { | ||
| return context | ||
| .path("/type/array/boolean") | ||
| .get({ ...operationOptionsToRequestParameters(options) }); | ||
| } | ||
|
|
||
| export async function _booleanValueGetDeserialize( | ||
| result: BooleanValueGet200Response, | ||
| ): Promise<boolean[]> { | ||
| if (result.status !== "200") { | ||
| throw createRestError(result); | ||
| } | ||
|
|
||
| return result.body; | ||
| } | ||
|
|
||
| export async function booleanValueGet( | ||
| context: Client, | ||
| options: BooleanValueGetOptions = { requestOptions: {} }, | ||
| ): Promise<boolean[]> { | ||
| const result = await _booleanValueGetSend(context, options); | ||
| return _booleanValueGetDeserialize(result); | ||
| } | ||
|
|
||
| export function _booleanValuePutSend( | ||
| context: Client, | ||
| body: boolean[], | ||
| options: BooleanValuePutOptions = { requestOptions: {} }, | ||
| ): StreamableMethod<BooleanValuePut204Response> { | ||
| return context | ||
| .path("/type/array/boolean") | ||
| .put({ ...operationOptionsToRequestParameters(options), body: body }); | ||
| } | ||
|
|
||
| export async function _booleanValuePutDeserialize( | ||
| result: BooleanValuePut204Response, | ||
| ): Promise<void> { | ||
| if (result.status !== "204") { | ||
| throw createRestError(result); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| export async function booleanValuePut( | ||
| context: Client, | ||
| body: boolean[], | ||
| options: BooleanValuePutOptions = { requestOptions: {} }, | ||
| ): Promise<void> { | ||
| const result = await _booleanValuePutSend(context, body, options); | ||
| return _booleanValuePutDeserialize(result); | ||
| } |
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.
Just found typespec can't not define this way playground link
Uh oh!
There was an error while loading. Please reload this page.
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 would assume elementTypes are all required, for nullable, since the current nullable logic has problem, I would prefer to have another independent pr to fix it. @MaryGao let me know if you have different thoughts.