Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
poly in example/test (#449)
Browse files Browse the repository at this point in the history
Co-authored-by: Qiaoqiao Zhang <55688292+qiaozha@users.noreply.github.com>
  • Loading branch information
changlong-liu and qiaozha authored Jun 23, 2020
1 parent b50e035 commit 549c834
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 65 deletions.
20 changes: 16 additions & 4 deletions src/plugins/azgenerator/CodeModelAzImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { serialize, deserialize, EnglishPluralizationService, pascalCase } from
import { Session, startSession, Host, Channel } from "@azure-tools/autorest-extension-base";
import { ToSnakeCase, deepCopy, ToJsonString, Capitalize, ToCamelCase, EscapeString, parseResourceId } from '../../utils/helper';
import { values } from "@azure-tools/linq";
import { GenerateDefaultTestScenario, ResourcePool, GenerateDefaultTestScenarioByDependency } from './ScenarioTool'
import { GenerateDefaultTestScenario, ResourcePool, GenerateDefaultTestScenarioByDependency, PrintTestScenario } from './ScenarioTool'
import { timingSafeEqual } from "crypto";
import { isNullOrUndefined, isArray } from "util";

Expand Down Expand Up @@ -855,6 +855,10 @@ export class CodeModelCliImpl implements CodeModelAz {
}
return polyOriginal;
}

public get Method_GetSplitOriginalOperation(): any {
return this.Method.extensions?.['cli-split-operation-original-operation'];
}
//=================================================================================================================
// Methods Parameters.
//
Expand Down Expand Up @@ -1822,8 +1826,8 @@ export class CodeModelCliImpl implements CodeModelAz {
let cliKey = model.Method.language['cli'].cliKey;
if (cliKey) {
let names = cliKey.split('#');
if (names.length > 1) {
return names[1];
if (names && names.length > 1) {
return names[names.length-1];
}
}
return '';
Expand All @@ -1833,7 +1837,7 @@ export class CodeModelCliImpl implements CodeModelAz {

function matchPolyClass(example: CommandExample, keyToMatch: string, valueToMatch: string) {
for (let param of example.Parameters) {
if (('--' + keyToMatch).toLowerCase() == param.name.toLowerCase() && typeof param.value == 'string') {
if ((('--' + keyToMatch).toLowerCase() == param.name.toLowerCase() || ('--' + keyToMatch + '-').toLowerCase() == param.name.toLowerCase()) && typeof param.value == 'string') {
return valueToMatch.toLowerCase() == param.value.toLowerCase();
}
}
Expand Down Expand Up @@ -1873,6 +1877,13 @@ export class CodeModelCliImpl implements CodeModelAz {
example.Parameters = this.ConvertToCliParameters(params);
example.MethodResponses = this.Method.responses || [];
example.Method_IsLongRun = this.Method.extensions?.['x-ms-long-running-operation'] ? true : false;
if (this.Method_GetSplitOriginalOperation && Object.keys(this.Examples).length>1) {
//filter example by name for generic createorupdate
if(this.Command_MethodName.toLowerCase()=="update" && !id.toLowerCase().endsWith("_update"))
return;
if(this.Command_MethodName.toLowerCase()!="update" && id.toLowerCase().endsWith("_update"))
return;
}
if (this.filterExampleByPoly(example_obj, example)) {
for (let i=0;i<example.Parameters.length; i++) {
if (this.isDiscriminator(example.Parameters[i].methodParam.value) )
Expand Down Expand Up @@ -2048,6 +2059,7 @@ export class CodeModelCliImpl implements CodeModelAz {
if (!this._configuredScenario) {
this._testScenario = GenerateDefaultTestScenarioByDependency(this.GetAllExamples(), this.resource_pool, this._testScenario);
this.SortExamplesByDependency();
PrintTestScenario(this._testScenario);
}

let commandParams = {};
Expand Down
22 changes: 15 additions & 7 deletions src/plugins/azgenerator/ScenarioTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ function MethodToOrder(httpMethod: string): number {

export function GenerateDefaultTestScenario(
examples: CommandExample[]): any[] {
console.warn("");
console.warn("NO TEST SCENARIO PROVIDED - DEFAULT WILL BE USED");
console.warn("ADD FOLLOWING SECTION TO readme.cli.md FILE TO MODIFY IT");
console.warn("--------------------------------------------------------");
console.warn(" test-scenario:");

let testScenario = [];

Expand Down Expand Up @@ -52,10 +47,8 @@ export function GenerateDefaultTestScenario(

for (var i = 0; i < sorted.length; i++) {
var example: CommandExample = sorted[i];
console.warn(" - name: " + example.Id);
testScenario.push({ name: example.Id })
}
console.warn("--------------------------------------------------------");
return testScenario;
}

Expand All @@ -82,6 +75,21 @@ export function GenerateDefaultTestScenarioByDependency(
});
}

export function PrintTestScenario(testScenario: any[]) {
console.warn("");
console.warn("NO TEST SCENARIO PROVIDED - DEFAULT WILL BE USED");
console.warn("ADD FOLLOWING SECTION TO readme.cli.md FILE TO MODIFY IT");
console.warn("--------------------------------------------------------");
console.warn(" test-scenario:");

for (var i = 0; i < testScenario.length; i++) {
var step: any = testScenario[i];
console.warn(" - name: " + step.name);
}
console.warn("--------------------------------------------------------");
}



const SUBSCRIPTIONS = "subscriptions";
const RESOUREGROUP = "resource-group";
Expand Down
1 change: 0 additions & 1 deletion src/test/scenarios/datafactory/configuration/readme.cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ cli:
- name: /Factories/post/Factories_GetGitHubAccessToken
- name: /Factories/patch/Factories_Update
- name: /IntegrationRuntimes/put/IntegrationRuntimes_Create
- name: /IntegrationRuntimes/put/IntegrationRuntimes_Create
- name: /IntegrationRuntimes/get/IntegrationRuntimes_Get
- name: /IntegrationRuntimes/get/IntegrationRuntimes_ListByFactory
- name: /IntegrationRuntimes/post/IntegrationRuntimes_CreateLinkedIntegrationRuntime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,12 @@
:\\"examplePipeline\\"}}],\\"typeProperties\\":{\\"recurrence\\":{\\"endTime\\":\\"2018-06-16T00:55:13.8441801Z\\",\\"f\
requency\\":\\"Minute\\",\\"interval\\":4,\\"startTime\\":\\"2018-06-16T00:39:13.8441801Z\\",\\"timeZone\\":\\"UTC\\"}}\
}" --name "exampleTrigger"
- name: Triggers_Update
text: |-
az datafactory trigger create --factory-name "exampleFactoryName" --resource-group \
"exampleResourceGroup" --properties "{\\"type\\":\\"ScheduleTrigger\\",\\"description\\":\\"Example \
description\\",\\"pipelines\\":[{\\"parameters\\":{\\"OutputBlobNameList\\":[\\"exampleoutput.csv\\"]},\\"pipelineRefer\
ence\\":{\\"type\\":\\"PipelineReference\\",\\"referenceName\\":\\"examplePipeline\\"}}],\\"typeProperties\\":{\\"recur\
rence\\":{\\"endTime\\":\\"2018-06-16T00:55:14.905167Z\\",\\"frequency\\":\\"Minute\\",\\"interval\\":4,\\"startTime\\"\
:\\"2018-06-16T00:39:14.905167Z\\",\\"timeZone\\":\\"UTC\\"}}}" --name "exampleTrigger"
"""

helps['datafactory trigger update'] = """
type: command
short-summary: Creates or updates a trigger.
examples:
- name: Triggers_Create
text: |-
az datafactory trigger update --factory-name "exampleFactoryName" --resource-group \
"exampleResourceGroup" --name "exampleTrigger"
- name: Triggers_Update
text: |-
az datafactory trigger update --factory-name "exampleFactoryName" --resource-group \
Expand Down Expand Up @@ -386,11 +374,6 @@
name: Required. ..
zones-inside: sample of simple array
examples:
- name: IntegrationRuntimes_Create
text: |-
az datafactory integration-runtime managed create --factory-name "exampleFactoryName" --description "A \
selfhosted integration runtime" --name "exampleIntegrationRuntime" --resource-group "exampleResourceGroup"
"""

helps['datafactory integration-runtime self-hosted'] = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,7 @@ def step__factories_patch_factories_update(test, rg):
# EXAMPLE: /IntegrationRuntimes/put/IntegrationRuntimes_Create
@try_manual
def step__integrationruntimes_put_integrationruntimes_create(test, rg):
test.cmd('az datafactory integration-runtime managed create '
'--factory-name "{exampleFactoryName}" '
'--description "A selfhosted integration runtime" '
'--name "{exampleIntegrationRuntime}" '
'--resource-group "{rg}"',
checks=[])


# EXAMPLE: /IntegrationRuntimes/put/IntegrationRuntimes_Create
@try_manual
def step__integrationruntimes_put_integrationruntimes_create(test, rg):
test.cmd('az datafactory integration-runtime managed create '
test.cmd('az datafactory integration-runtime self-hosted create '
'--factory-name "{exampleFactoryName}" '
'--description "A selfhosted integration runtime" '
'--name "{exampleIntegrationRuntime}" '
Expand Down Expand Up @@ -293,15 +282,10 @@ def step__triggers_put_triggers_create(test, rg):
# EXAMPLE: /Triggers/put/Triggers_Update
@try_manual
def step__triggers_put_triggers_update(test, rg):
test.cmd('az datafactory trigger create '
test.cmd('az datafactory trigger update '
'--factory-name "{exampleFactoryName}" '
'--resource-group "{rg}" '
'--properties "{{\\"type\\":\\"ScheduleTrigger\\",\\"description\\":\\"Example '
'description\\",\\"pipelines\\":[{{\\"parameters\\":{{\\"OutputBlobNameList\\":[\\"exampleoutput.csv\\"]}}'
',\\"pipelineReference\\":{{\\"type\\":\\"PipelineReference\\",\\"referenceName\\":\\"examplePipeline\\"}}'
'}}],\\"typeProperties\\":{{\\"recurrence\\":{{\\"endTime\\":\\"2018-06-16T00:55:14.905167Z\\",\\"frequenc'
'y\\":\\"Minute\\",\\"interval\\":4,\\"startTime\\":\\"2018-06-16T00:39:14.905167Z\\",\\"timeZone\\":\\"UT'
'C\\"}}}}}}" '
'--description "Example description" '
'--name "{exampleTrigger}"',
checks=[])

Expand Down Expand Up @@ -431,7 +415,6 @@ def call_scenario(test, rg):
step__factories_post_factories_getgithubaccesstoken(test, rg)
step__factories_patch_factories_update(test, rg)
step__integrationruntimes_put_integrationruntimes_create(test, rg)
step__integrationruntimes_put_integrationruntimes_create(test, rg)
step__integrationruntimes_get_integrationruntimes_get(test, rg)
step__integrationruntimes_get_integrationruntimes_listbyfactory(test, rg)
step__integrationruntimes_post_integrationruntimes_createlinkedintegrationruntime(test, rg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,6 @@
id: Resource Id
Multiple actions can be specified by using more than one --mesh argument.
examples:
- name: Create/Update Managed Network Peering Policy
text: |-
az managed-network managed-network-peering-policy mesh-topology create --managed-network-name \
"myManagedNetwork" --policy-name "myHubAndSpoke" --hub id="/subscriptions/subscriptionB/resourceGroups/myResourceGroup/\
providers/Microsoft.Network/virtualNetworks/myHubVnet" --spokes id="/subscriptions/subscriptionB/resourceGroups/myResou\
rceGroup/providers/Microsoft.ManagedNetwork/managedNetworks/myManagedNetwork/managedNetworkGroups/myManagedNetworkGroup\
1" --resource-group "myResourceGroup"
"""

helps['managed-network managed-network-peering-policy hub-and-spoke-topology update'] = """
Expand Down Expand Up @@ -437,14 +429,6 @@
id: Resource Id
Multiple actions can be specified by using more than one --mesh argument.
examples:
- name: Create/Update Managed Network Peering Policy
text: |-
az managed-network managed-network-peering-policy mesh-topology update --managed-network-name \
"myManagedNetwork" --policy-name "myHubAndSpoke" --hub id="/subscriptions/subscriptionB/resourceGroups/myResourceGroup/\
providers/Microsoft.Network/virtualNetworks/myHubVnet" --spokes id="/subscriptions/subscriptionB/resourceGroups/myResou\
rceGroup/providers/Microsoft.ManagedNetwork/managedNetworks/myManagedNetwork/managedNetworkGroups/myManagedNetworkGroup\
1" --resource-group "myResourceGroup"
"""

helps['managed-network managed-network-peering-policy delete'] = """
Expand Down

0 comments on commit 549c834

Please sign in to comment.