-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add coverage for repeatability (#2112)
- Loading branch information
1 parent
8fdc016
commit cafd43f
Showing
16 changed files
with
286 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
39 changes: 39 additions & 0 deletions
39
...t/modularIntegration/generated/headers/repeatability/generated/src/RepeatabilityClient.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { Pipeline } from "@azure/core-rest-pipeline"; | ||
import { | ||
immediateSuccess, | ||
createRepeatability, | ||
RepeatabilityClientOptions, | ||
RepeatabilityContext, | ||
} from "./api/index.js"; | ||
import { ImmediateSuccessOptions } from "./models/options.js"; | ||
|
||
export { RepeatabilityClientOptions } from "./api/RepeatabilityContext.js"; | ||
|
||
export class RepeatabilityClient { | ||
private _client: RepeatabilityContext; | ||
/** The pipeline used by this client to make requests */ | ||
public readonly pipeline: Pipeline; | ||
|
||
/** Illustrates OASIS repeatability headers */ | ||
constructor(options: RepeatabilityClientOptions = {}) { | ||
this._client = createRepeatability(options); | ||
this.pipeline = this._client.pipeline; | ||
} | ||
|
||
/** Check we recognize Repeatability-Request-ID and Repeatability-First-Sent. */ | ||
immediateSuccess( | ||
repeatabilityRequestID: string, | ||
repeatabilityFirstSent: Date, | ||
options: ImmediateSuccessOptions = { requestOptions: {} } | ||
): Promise<void> { | ||
return immediateSuccess( | ||
this._client, | ||
repeatabilityRequestID, | ||
repeatabilityFirstSent, | ||
options | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ularIntegration/generated/headers/repeatability/generated/src/api/RepeatabilityContext.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { ClientOptions } from "@azure-rest/core-client"; | ||
import { RepeatabilityContext } from "../rest/index.js"; | ||
import getClient from "../rest/index.js"; | ||
|
||
export interface RepeatabilityClientOptions extends ClientOptions {} | ||
|
||
export { RepeatabilityContext } from "../rest/index.js"; | ||
|
||
/** Illustrates OASIS repeatability headers */ | ||
export function createRepeatability( | ||
options: RepeatabilityClientOptions = {} | ||
): RepeatabilityContext { | ||
const clientContext = getClient(options); | ||
return clientContext; | ||
} |
9 changes: 9 additions & 0 deletions
9
...pec-ts/test/modularIntegration/generated/headers/repeatability/generated/src/api/index.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
export { immediateSuccess } from "./operations.js"; | ||
export { | ||
createRepeatability, | ||
RepeatabilityClientOptions, | ||
RepeatabilityContext, | ||
} from "./RepeatabilityContext.js"; |
55 changes: 55 additions & 0 deletions
55
...s/test/modularIntegration/generated/headers/repeatability/generated/src/api/operations.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { | ||
ImmediateSuccess204Response, | ||
RepeatabilityContext as Client, | ||
} from "../rest/index.js"; | ||
import { | ||
StreamableMethod, | ||
operationOptionsToRequestParameters, | ||
} from "@azure-rest/core-client"; | ||
import { ImmediateSuccessOptions } from "../models/options.js"; | ||
|
||
export function _immediateSuccessSend( | ||
context: Client, | ||
repeatabilityRequestID: string, | ||
repeatabilityFirstSent: Date, | ||
options: ImmediateSuccessOptions = { requestOptions: {} } | ||
): StreamableMethod<ImmediateSuccess204Response> { | ||
return context | ||
.path("/special-headers/repeatability/immediateSuccess") | ||
.post({ | ||
...operationOptionsToRequestParameters(options), | ||
headers: { | ||
"Repeatability-Request-ID": repeatabilityRequestID, | ||
"Repeatability-First-Sent": repeatabilityFirstSent.toUTCString(), | ||
}, | ||
}); | ||
} | ||
|
||
export async function _immediateSuccessDeserialize( | ||
result: ImmediateSuccess204Response | ||
): Promise<void> { | ||
if (result.status !== "204") { | ||
throw result.body; | ||
} | ||
|
||
return; | ||
} | ||
|
||
/** Check we recognize Repeatability-Request-ID and Repeatability-First-Sent. */ | ||
export async function immediateSuccess( | ||
context: Client, | ||
repeatabilityRequestID: string, | ||
repeatabilityFirstSent: Date, | ||
options: ImmediateSuccessOptions = { requestOptions: {} } | ||
): Promise<void> { | ||
const result = await _immediateSuccessSend( | ||
context, | ||
repeatabilityRequestID, | ||
repeatabilityFirstSent, | ||
options | ||
); | ||
return _immediateSuccessDeserialize(result); | ||
} |
8 changes: 8 additions & 0 deletions
8
...ypespec-ts/test/modularIntegration/generated/headers/repeatability/generated/src/index.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
export { | ||
RepeatabilityClient, | ||
RepeatabilityClientOptions, | ||
} from "./RepeatabilityClient.js"; | ||
export { ImmediateSuccessOptions } from "./models/index.js"; |
5 changes: 5 additions & 0 deletions
5
...pespec-ts/test/modularIntegration/generated/headers/repeatability/generated/src/logger.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { createClientLogger } from "@azure/logger"; | ||
export const logger = createClientLogger("headers-repeatability"); |
4 changes: 4 additions & 0 deletions
4
...-ts/test/modularIntegration/generated/headers/repeatability/generated/src/models/index.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
export { ImmediateSuccessOptions } from "./options.js"; |
6 changes: 6 additions & 0 deletions
6
...s/test/modularIntegration/generated/headers/repeatability/generated/src/models/options.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { OperationOptions } from "@azure-rest/core-client"; | ||
|
||
export interface ImmediateSuccessOptions extends OperationOptions {} |
22 changes: 22 additions & 0 deletions
22
...odularIntegration/generated/headers/repeatability/generated/src/rest/clientDefinitions.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { ImmediateSuccessParameters } from "./parameters.js"; | ||
import { ImmediateSuccess204Response } from "./responses.js"; | ||
import { Client, StreamableMethod } from "@azure-rest/core-client"; | ||
|
||
export interface ImmediateSuccess { | ||
/** Check we recognize Repeatability-Request-ID and Repeatability-First-Sent. */ | ||
post( | ||
options: ImmediateSuccessParameters | ||
): StreamableMethod<ImmediateSuccess204Response>; | ||
} | ||
|
||
export interface Routes { | ||
/** Resource for '/special-headers/repeatability/immediateSuccess' has methods for the following verbs: post */ | ||
(path: "/special-headers/repeatability/immediateSuccess"): ImmediateSuccess; | ||
} | ||
|
||
export type RepeatabilityContext = Client & { | ||
path: Routes; | ||
}; |
11 changes: 11 additions & 0 deletions
11
...ec-ts/test/modularIntegration/generated/headers/repeatability/generated/src/rest/index.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import RepeatabilityClient from "./repeatabilityClient.js"; | ||
|
||
export * from "./repeatabilityClient.js"; | ||
export * from "./parameters.js"; | ||
export * from "./responses.js"; | ||
export * from "./clientDefinitions.js"; | ||
|
||
export default RepeatabilityClient; |
17 changes: 17 additions & 0 deletions
17
.../test/modularIntegration/generated/headers/repeatability/generated/src/rest/parameters.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { RawHttpHeadersInput } from "@azure/core-rest-pipeline"; | ||
import { RequestParameters } from "@azure-rest/core-client"; | ||
|
||
export interface ImmediateSuccessHeaders { | ||
"Repeatability-Request-ID": string; | ||
"Repeatability-First-Sent": string; | ||
} | ||
|
||
export interface ImmediateSuccessHeaderParam { | ||
headers: RawHttpHeadersInput & ImmediateSuccessHeaders; | ||
} | ||
|
||
export type ImmediateSuccessParameters = ImmediateSuccessHeaderParam & | ||
RequestParameters; |
35 changes: 35 additions & 0 deletions
35
...ularIntegration/generated/headers/repeatability/generated/src/rest/repeatabilityClient.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { getClient, ClientOptions } from "@azure-rest/core-client"; | ||
import { logger } from "../logger.js"; | ||
import { RepeatabilityContext } from "./clientDefinitions.js"; | ||
|
||
/** | ||
* Initialize a new instance of `RepeatabilityContext` | ||
* @param options - the parameter for all optional parameters | ||
*/ | ||
export default function createClient( | ||
options: ClientOptions = {} | ||
): RepeatabilityContext { | ||
const baseUrl = options.baseUrl ?? `http://localhost:3000`; | ||
options.apiVersion = options.apiVersion ?? "1.0.0"; | ||
const userAgentInfo = `azsdk-js-headers-repeatability-rest/1.0.0-beta.1`; | ||
const userAgentPrefix = | ||
options.userAgentOptions && options.userAgentOptions.userAgentPrefix | ||
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` | ||
: `${userAgentInfo}`; | ||
options = { | ||
...options, | ||
userAgentOptions: { | ||
userAgentPrefix, | ||
}, | ||
loggingOptions: { | ||
logger: options.loggingOptions?.logger ?? logger.info, | ||
}, | ||
}; | ||
|
||
const client = getClient(baseUrl, options) as RepeatabilityContext; | ||
|
||
return client; | ||
} |
16 changes: 16 additions & 0 deletions
16
...s/test/modularIntegration/generated/headers/repeatability/generated/src/rest/responses.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { RawHttpHeaders } from "@azure/core-rest-pipeline"; | ||
import { HttpResponse } from "@azure-rest/core-client"; | ||
|
||
export interface ImmediateSuccess204Headers { | ||
/** Indicates whether the repeatable request was accepted or rejected. */ | ||
"repeatability-result"?: "accepted" | "rejected"; | ||
} | ||
|
||
/** There is no content to send for this request, but the headers may be useful. */ | ||
export interface ImmediateSuccess204Response extends HttpResponse { | ||
status: "204"; | ||
headers: RawHttpHeaders & ImmediateSuccess204Headers; | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/typespec-ts/test/modularIntegration/generated/headers/repeatability/tspconfig.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
emit: | ||
- "@azure-tools/typespec-ts" | ||
options: | ||
"@azure-tools/typespec-ts": | ||
generateMetadata: false | ||
generateTest: false | ||
azureSdkForJs: false | ||
isModularLibrary: true | ||
hierarchyClient: false | ||
"emitter-output-dir": "{project-root}/generated" | ||
packageDetails: | ||
name: "@msinternal/headers-repeatability" |
25 changes: 25 additions & 0 deletions
25
packages/typespec-ts/test/modularIntegration/headersRepeatability.spec.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { RepeatabilityClient } from "./generated/headers/repeatability/generated/src/index.js"; | ||
import { assert } from "chai"; | ||
|
||
describe("Repeatability Client", () => { | ||
let client: RepeatabilityClient; | ||
|
||
beforeEach(() => { | ||
client = new RepeatabilityClient({ | ||
allowInsecureConnection: true | ||
}); | ||
}); | ||
|
||
it("should add client-request-id and date in header", async () => { | ||
try { | ||
const requestID = "86aede1f-96fa-4e7f-b1e1-bf8a947cb804"; | ||
const result = await client.immediateSuccess( | ||
requestID, | ||
new Date("Mon, 13 Nov 2023 14:38:00 GMT") | ||
); | ||
assert.isUndefined(result); | ||
} catch (err) { | ||
assert.fail(err as string); | ||
} | ||
}); | ||
}); |