Skip to content

Commit

Permalink
gotest feature and fix from service team (#1197)
Browse files Browse the repository at this point in the history
* fix example lost when include-x-ms-examples-original-file false

* add config for not do go lint

* flip lint flag

* fix duplication name in different operation group issue

* fix wrong pageable usage when response name is same with page item property name

* regen update
  • Loading branch information
tadelesh committed Apr 10, 2024
1 parent 6df5f68 commit 8264019
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 83 deletions.

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.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/autorest.gotest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ File prefix for auto-generated examples.

File prefix for auto-generated tests.

### --gotest.skip-lint

Whether skip lint go file after generation.

## Autorest Pipeline Configurations

```yaml $(go)
Expand Down
2 changes: 2 additions & 0 deletions packages/autorest.gotest/src/common/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum Config {
testFilePrefix = 'test-file-prefix',
sendExampleId = 'testmodeler.mock.send-example-id',
verifyResponse = 'testmodeler.mock.verify-response',
skipLint = 'gotest.skip-lint'
}

export const configDefaults = {
Expand All @@ -34,4 +35,5 @@ export const configDefaults = {
[Config.filePrefix]: '',
[Config.exampleFilePrefix]: '',
[Config.testFilePrefix]: '',
[Config.skipLint]: false,
};
20 changes: 11 additions & 9 deletions packages/autorest.gotest/src/generator/goLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as path from 'path';
import { AutorestExtensionHost } from '@autorest/extension-base';
import { Config, configDefaults } from '../common/constant';
import { Helper } from '@autorest/testmodeler/dist/src/util/helper';
import { TestConfig } from '@autorest/testmodeler/dist/src/common/testConfig';
import { Helper } from '@autorest/testmodeler/dist/src/util/helper';
import * as path from 'path';
import { Config, configDefaults } from '../common/constant';

export async function processRequest(host: AutorestExtensionHost): Promise<void> {
const testConfig = new TestConfig(await host.GetValue(''), configDefaults);
const files = await host.listInputs();
Helper.execSync('go install golang.org/x/tools/cmd/goimports@latest');
for (const outputFile of files) {
if (outputFile.endsWith('.go')) {
const pathName = path.join(testConfig.getValue(Config.outputFolder), outputFile);
Helper.execSync(`goimports -w ${pathName}`);
if (!testConfig.getValue(Config.skipLint)) {
const files = await host.listInputs();
Helper.execSync('go install golang.org/x/tools/cmd/goimports@latest');
for (const outputFile of files) {
if (outputFile.endsWith('.go')) {
const pathName = path.join(testConfig.getValue(Config.outputFolder), outputFile);
Helper.execSync(`goimports -w ${pathName}`);
}
}
}
}
3 changes: 3 additions & 0 deletions packages/autorest.gotest/src/generator/mockTestGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export class MockTestDataRender extends BaseDataRender {
for (const property of schemaResponse.schema['properties']) {
if (property.serializedName === valueName) {
example.pageableItemName = property.language.go.name;
if (schemaResponse.schema.language.go.name === property.language.go.name) {
example.pageableItemName = `${property.language.go.name}.${example.pageableItemName}`;
}
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/autorest.gotest/src/template/exampleTest.go.njk
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
)
{{imports}}
{%- set allExamples = [] %}
{%- for exampleGroup in exampleGroups %}
{%- set allExamples = [] %}
{%- for example in exampleGroup.examples %}
{%- if allExamples.indexOf(example.originalFile)<0 %}
{%- set _ = allExamples.push(example.originalFile) %}
{%- if allExamples.indexOf(example.name)<0 %}
{%- set _ = allExamples.push(example.name) %}
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/{{swaggerCommit}}/{{example.originalFile}}
func Example{{example.operationGroup.language.go.clientName}}_{{example.opName}}{% if exampleGroup.examples.length>1 %}_{{jsFunc.getExampleSuffix(example.name)}}{% endif %}() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
Expand Down

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
Expand Up @@ -15653,24 +15653,24 @@ schemas:
- name
language:
default:
name: AmlOperationListResultValue
name: AmlOperations
description: List of AML workspace operations supported by the AML workspace resource provider.
go:
name: '[]*AmlOperation'
description: List of AML workspace operations supported by the AML workspace resource provider.
elementIsPtr: true
marshallingFormat: json
protocol: {}
serializedName: value
serializedName: amlOperations
extensions:
x-ms-identifiers:
- name
language: &ref_2498
default:
name: value
name: amlOperations
description: List of AML workspace operations supported by the AML workspace resource provider.
go:
name: Value
name: AmlOperations
description: List of AML workspace operations supported by the AML workspace resource provider.
byValue: true
protocol: {}
Expand All @@ -15680,12 +15680,12 @@ schemas:
- output
language:
default:
name: AmlOperationListResult
name: AmlOperations
description: An array of operations supported by the resource provider.
namespace: ''
go:
name: AmlOperationListResult
description: AmlOperationListResult - An array of operations supported by the resource provider.
name: AmlOperations
description: AmlOperations - An array of operations supported by the resource provider.
hasArrayMap: true
marshallingFormat: json
namespace: ''
Expand Down Expand Up @@ -38673,7 +38673,7 @@ operationGroups:
responses:
'200':
body:
value:
amlOperations:
- name: Microsoft.MachineLearningServices/workspaces/write
display:
operation: Create/Update Machine Learning workspaces
Expand All @@ -38690,12 +38690,14 @@ operationGroups:
provider: Microsoft MachineLearningServices
resource: workspaces
x-ms-pageable:
itemName: amlOperations
nextLinkName: null
language:
default:
name: List
description: Lists all of the available Azure Machine Learning Workspaces REST API operations.
paging:
itemName: amlOperations
nextLinkName: null
go:
name: List
Expand All @@ -38722,6 +38724,7 @@ operationGroups:
go: *ref_1287
protocol: {}
paging:
itemName: amlOperations
nextLinkName: null
protocolNaming:
internalMethod: listOperation
Expand All @@ -38732,10 +38735,10 @@ operationGroups:
properties:
- &ref_1289
schema: *ref_1285
serializedName: AmlOperationListResult
serializedName: AmlOperations
language:
default: &ref_1288
name: AmlOperationListResult
name: AmlOperations
description: An array of operations supported by the resource provider.
byValue: true
embeddedType: true
Expand Down Expand Up @@ -70643,7 +70646,7 @@ testModel:
schema: *ref_1285
parentsValue: {}
properties:
value:
amlOperations:
schema: *ref_1199
elements:
- schema: *ref_61
Expand Down
Loading

0 comments on commit 8264019

Please sign in to comment.