Skip to content

Commit 8f5b8a9

Browse files
authored
add-encode-byte-cadl-ranch-test (#2003)
* add-encode-byte-cadl-ranch-test * resolve comments
1 parent c138441 commit 8f5b8a9

12 files changed

Lines changed: 632 additions & 0 deletions

File tree

packages/typespec-ts/test/commands/cadl-ranch-list.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const rlcTsps: TypeSpecRanchConfig[] = [
2121
outputPath: "parameters/body-optionality",
2222
inputPath: "parameters/body-optionality"
2323
},
24+
{
25+
outputPath: "encode/bytes",
26+
inputPath: "encode/bytes"
27+
},
2428
{
2529
outputPath: "encode/duration",
2630
inputPath: "encode/duration"
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
import { assert } from "chai";
2+
import EncodeBytesClientFactory, {
3+
BytesClient
4+
} from "./generated/encode/bytes/src/index.js";
5+
import { buildCsvCollection } from "./generated/encode/bytes/src/serializeHelper.js";
6+
describe("EncodeDatetimeClient Rest Client", () => {
7+
let client: BytesClient;
8+
9+
beforeEach(() => {
10+
client = EncodeBytesClientFactory({
11+
allowInsecureConnection: true,
12+
retryOptions: {
13+
maxRetries: 0
14+
}
15+
});
16+
});
17+
18+
describe("query", () => {
19+
it(`should get bytes`, async () => {
20+
try {
21+
const result = await client.path(`/encode/bytes/query/default`).get({
22+
queryParameters: {
23+
value: "dGVzdA=="
24+
}
25+
});
26+
assert.strictEqual(result.status, "204");
27+
} catch (err) {
28+
assert.fail(err as string);
29+
}
30+
});
31+
32+
it(`should get bytes base64 encoding`, async () => {
33+
try {
34+
const result = await client.path(`/encode/bytes/query/base64`).get({
35+
queryParameters: {
36+
value: "dGVzdA=="
37+
}
38+
});
39+
assert.strictEqual(result.status, "204");
40+
} catch (err) {
41+
assert.fail(err as string);
42+
}
43+
});
44+
45+
it(`should get bytes base64url encoding`, async () => {
46+
try {
47+
const result = await client.path(`/encode/bytes/query/base64url`).get({
48+
queryParameters: {
49+
value: "dGVzdA"
50+
}
51+
});
52+
assert.strictEqual(result.status, "204");
53+
} catch (err) {
54+
assert.fail(err as string);
55+
}
56+
});
57+
58+
it(`should get bytes base64url-array`, async () => {
59+
try {
60+
const result = await client
61+
.path(`/encode/bytes/query/base64url-array`)
62+
.get({
63+
queryParameters: {
64+
value: ["dGVzdA", "dGVzdA"]
65+
}
66+
});
67+
assert.strictEqual(result.status, "204");
68+
} catch (err) {
69+
assert.fail(err as string);
70+
}
71+
});
72+
73+
});
74+
75+
76+
describe("property", () => {
77+
it(`should post bytes`, async () => {
78+
try {
79+
const result = await client.path(`/encode/bytes/property/default`).post({
80+
body: {
81+
value: "dGVzdA=="
82+
}
83+
});
84+
assert.strictEqual(result.status, "200");
85+
} catch (err) {
86+
assert.fail(err as string);
87+
}
88+
});
89+
90+
it(`should post bytes base64 encoding`, async () => {
91+
try {
92+
const result = await client.path(`/encode/bytes/property/base64`).post({
93+
body: {
94+
value: "dGVzdA=="
95+
}
96+
});
97+
assert.strictEqual(result.status, "200");
98+
} catch (err) {
99+
assert.fail(err as string);
100+
}
101+
});
102+
103+
it(`should post bytes base64url encoding`, async () => {
104+
try {
105+
const result = await client.path(`/encode/bytes/property/base64url`).post({
106+
body: {
107+
value: "dGVzdA"
108+
}
109+
});
110+
assert.strictEqual(result.status, "200");
111+
} catch (err) {
112+
assert.fail(err as string);
113+
}
114+
});
115+
116+
it(`should post bytes base64url array`, async () => {
117+
try {
118+
const result = await client
119+
.path(`/encode/bytes/property/base64url-array`)
120+
.post({
121+
body: {
122+
value: ["dGVzdA", "dGVzdA"]
123+
}
124+
});
125+
assert.strictEqual(result.status, "200");
126+
} catch (err) {
127+
assert.fail(err as string);
128+
}
129+
});
130+
131+
});
132+
133+
describe("header", () => {
134+
it(`should get bytes`, async () => {
135+
try {
136+
const result = await client.path(`/encode/bytes/header/default`).get({
137+
headers: {
138+
value: "dGVzdA=="
139+
}
140+
});
141+
assert.strictEqual(result.status, "204");
142+
} catch (err) {
143+
assert.fail(err as string);
144+
}
145+
});
146+
147+
it(`should get bytes base64 encoding`, async () => {
148+
try {
149+
const result = await client.path(`/encode/bytes/header/base64`).get({
150+
headers: {
151+
value: "dGVzdA=="
152+
}
153+
});
154+
assert.strictEqual(result.status, "204");
155+
} catch (err) {
156+
assert.fail(err as string);
157+
}
158+
});
159+
160+
it(`should get bytes base64url encoding`, async () => {
161+
try {
162+
const result = await client.path(`/encode/bytes/header/base64url`).get({
163+
headers: {
164+
value: "dGVzdA"
165+
}
166+
});
167+
assert.strictEqual(result.status, "204");
168+
} catch (err) {
169+
assert.fail(err as string);
170+
}
171+
});
172+
173+
it(`should get bytes base64url-array`, async () => {
174+
try {
175+
const result = await client
176+
.path(`/encode/bytes/header/base64url-array`)
177+
.get({
178+
headers: {
179+
value: buildCsvCollection(["dGVzdA", "dGVzdA"])
180+
}
181+
});
182+
assert.strictEqual(result.status, "204");
183+
} catch (err) {
184+
assert.fail(err as string);
185+
}
186+
});
187+
188+
});
189+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { getClient, ClientOptions } from "@azure-rest/core-client";
5+
import { logger } from "./logger";
6+
import { BytesClient } from "./clientDefinitions";
7+
8+
/**
9+
* Initialize a new instance of `BytesClient`
10+
* @param options - the parameter for all optional parameters
11+
*/
12+
export default function createClient(options: ClientOptions = {}): BytesClient {
13+
const baseUrl = options.baseUrl ?? `http://localhost:3000`;
14+
options.apiVersion = options.apiVersion ?? "1.0.0";
15+
const userAgentInfo = `azsdk-js-encode-bytes-rest/1.0.0-beta.1`;
16+
const userAgentPrefix =
17+
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
18+
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
19+
: `${userAgentInfo}`;
20+
options = {
21+
...options,
22+
userAgentOptions: {
23+
userAgentPrefix,
24+
},
25+
loggingOptions: {
26+
logger: options.loggingOptions?.logger ?? logger.info,
27+
},
28+
};
29+
30+
const client = getClient(baseUrl, options) as BytesClient;
31+
32+
return client;
33+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import {
5+
QueryDefaultParameters,
6+
QueryBase64Parameters,
7+
QueryBase64urlParameters,
8+
QueryBase64urlArrayParameters,
9+
PropertyDefaultParameters,
10+
PropertyBase64Parameters,
11+
PropertyBase64urlParameters,
12+
PropertyBase64urlArrayParameters,
13+
HeaderDefaultParameters,
14+
HeaderBase64Parameters,
15+
HeaderBase64urlParameters,
16+
HeaderBase64urlArrayParameters,
17+
} from "./parameters";
18+
import {
19+
QueryDefault204Response,
20+
QueryBase64204Response,
21+
QueryBase64url204Response,
22+
QueryBase64urlArray204Response,
23+
PropertyDefault200Response,
24+
PropertyBase64200Response,
25+
PropertyBase64url200Response,
26+
PropertyBase64urlArray200Response,
27+
HeaderDefault204Response,
28+
HeaderBase64204Response,
29+
HeaderBase64url204Response,
30+
HeaderBase64urlArray204Response,
31+
} from "./responses";
32+
import { Client, StreamableMethod } from "@azure-rest/core-client";
33+
34+
export interface QueryDefault {
35+
get(
36+
options: QueryDefaultParameters
37+
): StreamableMethod<QueryDefault204Response>;
38+
}
39+
40+
export interface QueryBase64 {
41+
get(options: QueryBase64Parameters): StreamableMethod<QueryBase64204Response>;
42+
}
43+
44+
export interface QueryBase64url {
45+
get(
46+
options: QueryBase64urlParameters
47+
): StreamableMethod<QueryBase64url204Response>;
48+
}
49+
50+
export interface QueryBase64urlArray {
51+
get(
52+
options: QueryBase64urlArrayParameters
53+
): StreamableMethod<QueryBase64urlArray204Response>;
54+
}
55+
56+
export interface PropertyDefault {
57+
post(
58+
options: PropertyDefaultParameters
59+
): StreamableMethod<PropertyDefault200Response>;
60+
}
61+
62+
export interface PropertyBase64 {
63+
post(
64+
options: PropertyBase64Parameters
65+
): StreamableMethod<PropertyBase64200Response>;
66+
}
67+
68+
export interface PropertyBase64url {
69+
post(
70+
options: PropertyBase64urlParameters
71+
): StreamableMethod<PropertyBase64url200Response>;
72+
}
73+
74+
export interface PropertyBase64urlArray {
75+
post(
76+
options: PropertyBase64urlArrayParameters
77+
): StreamableMethod<PropertyBase64urlArray200Response>;
78+
}
79+
80+
export interface HeaderDefault {
81+
get(
82+
options: HeaderDefaultParameters
83+
): StreamableMethod<HeaderDefault204Response>;
84+
}
85+
86+
export interface HeaderBase64 {
87+
get(
88+
options: HeaderBase64Parameters
89+
): StreamableMethod<HeaderBase64204Response>;
90+
}
91+
92+
export interface HeaderBase64url {
93+
get(
94+
options: HeaderBase64urlParameters
95+
): StreamableMethod<HeaderBase64url204Response>;
96+
}
97+
98+
export interface HeaderBase64urlArray {
99+
get(
100+
options: HeaderBase64urlArrayParameters
101+
): StreamableMethod<HeaderBase64urlArray204Response>;
102+
}
103+
104+
export interface Routes {
105+
/** Resource for '/encode/bytes/query/default' has methods for the following verbs: get */
106+
(path: "/encode/bytes/query/default"): QueryDefault;
107+
/** Resource for '/encode/bytes/query/base64' has methods for the following verbs: get */
108+
(path: "/encode/bytes/query/base64"): QueryBase64;
109+
/** Resource for '/encode/bytes/query/base64url' has methods for the following verbs: get */
110+
(path: "/encode/bytes/query/base64url"): QueryBase64url;
111+
/** Resource for '/encode/bytes/query/base64url-array' has methods for the following verbs: get */
112+
(path: "/encode/bytes/query/base64url-array"): QueryBase64urlArray;
113+
/** Resource for '/encode/bytes/property/default' has methods for the following verbs: post */
114+
(path: "/encode/bytes/property/default"): PropertyDefault;
115+
/** Resource for '/encode/bytes/property/base64' has methods for the following verbs: post */
116+
(path: "/encode/bytes/property/base64"): PropertyBase64;
117+
/** Resource for '/encode/bytes/property/base64url' has methods for the following verbs: post */
118+
(path: "/encode/bytes/property/base64url"): PropertyBase64url;
119+
/** Resource for '/encode/bytes/property/base64url-array' has methods for the following verbs: post */
120+
(path: "/encode/bytes/property/base64url-array"): PropertyBase64urlArray;
121+
/** Resource for '/encode/bytes/header/default' has methods for the following verbs: get */
122+
(path: "/encode/bytes/header/default"): HeaderDefault;
123+
/** Resource for '/encode/bytes/header/base64' has methods for the following verbs: get */
124+
(path: "/encode/bytes/header/base64"): HeaderBase64;
125+
/** Resource for '/encode/bytes/header/base64url' has methods for the following verbs: get */
126+
(path: "/encode/bytes/header/base64url"): HeaderBase64url;
127+
/** Resource for '/encode/bytes/header/base64url-array' has methods for the following verbs: get */
128+
(path: "/encode/bytes/header/base64url-array"): HeaderBase64urlArray;
129+
}
130+
131+
export type BytesClient = Client & {
132+
path: Routes;
133+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import BytesClient from "./bytesClient";
5+
6+
export * from "./bytesClient";
7+
export * from "./parameters";
8+
export * from "./responses";
9+
export * from "./clientDefinitions";
10+
export * from "./models";
11+
export * from "./outputModels";
12+
13+
export default BytesClient;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { createClientLogger } from "@azure/logger";
5+
export const logger = createClientLogger("encode-bytes");

0 commit comments

Comments
 (0)