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

enable min-test-scenario by configuration #694

Merged
merged 1 commit into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 6 additions & 30 deletions doc/04-scenario-test-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,35 +397,11 @@ az:
...
randomize-names: true
~~~
## How to write readme.cli.md foramt
As shown below, Testcases with the same keyword are grouped together, and it is desirable that each group contain only testCases with that group name
~~~
## CLI

These settings don't need to apply `--cli` on the command line.

``` yaml $(cli)
cli:
cli-name: managednetwork
test-scenario:
- ManagedNetworks:
- name: ManagedNetworksPut
- name: ManagementNetworkGroupsPut
- name: ManagedNetworkPeeringPoliciesPut
- name: ManagedNetworksGet
- name: ManagedNetworksListByResourceGroup
- name: ManagedNetworksListBySubscription
- name: ManagedNetworksDelete
- name: ManagementNetworkGroupsGet
- name: ManagedNetworksGroupsListByManagedNetwork
- name: ManagedNetworkPeeringPoliciesGet
- name: ManagedNetworkPeeringPoliciesListByManagedNetwork
- name: ManagedNetworkPeeringPoliciesDelete
- name: ManagementNetworkGroupsDelete
- ScopeAssignments:
- name: ScopeAssignmentsPut
- name: ScopeAssignmentsGet
- name: ScopeAssignmentsList
- name: ScopeAssignmentsDelete
```
## How to generate test-scenario for required parameters
You can ask autorest.az to generate minimal tests (using only required parameters for all step). To enable the minimal test scenario, please add gen-min-test configuration like below in readme.az.md
~~~
az:
...
gen-min-test: true
~~~
2 changes: 1 addition & 1 deletion src/plugins/azgenerator/CodeModelAz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,5 @@ export interface CodeModelAz {

// readme config
CliCoreLib: string;

GenMinTest: boolean;
}
6 changes: 6 additions & 0 deletions src/plugins/azgenerator/CodeModelAzImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ export class CodeModelCliImpl implements CodeModelAz {
return true;
}

public get GenMinTest(): boolean {
let genMinTest = this.options?.['gen-min-test'];
if (genMinTest) return true;
return false;
}

public GetResourcePool(): ResourcePool {
return this.resource_pool;
}
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/azgenerator/templates/tests/CliTestScenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class CliTestScenario extends TemplateBase {
outputFunc.push("");
}
buildSenario(this.header, funcScenario, false);
buildSenario(this.header, funcMinScenario, true);
if (model.GenMinTest) buildSenario(this.header, funcMinScenario, true);

class_info.push(" def __init__(self, *args, **kwargs):");
class_info.push(` super(${testClassName}, self).__init__(*args, **kwargs)`);
Expand All @@ -172,7 +172,10 @@ export class CliTestScenario extends TemplateBase {
return ret;
}
let testCaseName = this.groupName + "_" + scenarioName;
this.scenarios.push(...steps.concat(funcScenario, funcMinScenario, class_info, buildTestcase(testCaseName, false), buildTestcase(testCaseName, true)));
this.scenarios.push(...steps.concat(funcScenario, funcMinScenario, class_info, buildTestcase(testCaseName, false)));
if (model.GenMinTest) {
this.scenarios.push(...buildTestcase(testCaseName, true));
}
}

private EndGenerateAzureCliTestScenario(): string[] {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/azgenerator/templates/tests/CliTestStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class CliTestStep extends TemplateBase {
steps.push("");
}
create_step();
create_step(true);
if (model.GenMinTest) create_step(true);
}
else if (functionName) {
steps.push(`# Env ${functionName}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ def step_attestation_provider_show(test, rg, rg_2, rg_3, checks=None):
checks=checks)


@try_manual
def step_attestation_provider_show_min(test, rg, rg_2, rg_3, checks=None):
return step_attestation_provider_show(test, rg, rg_2, rg_3, checks)


# EXAMPLE: /AttestationProviders/get/AttestationProviders_List
@try_manual
def step_attestation_provider_provider_list(test, rg, rg_2, rg_3, checks=None):
Expand All @@ -38,11 +33,6 @@ def step_attestation_provider_provider_list(test, rg, rg_2, rg_3, checks=None):
checks=checks)


@try_manual
def step_attestation_provider_provider_list_min(test, rg, rg_2, rg_3, checks=None):
return step_attestation_provider_provider_list(test, rg, rg_2, rg_3, checks)


# EXAMPLE: /AttestationProviders/get/AttestationProviders_ListByResourceGroup
@try_manual
def step_attestation_provider_provider_list2(test, rg, rg_2, rg_3, checks=None):
Expand All @@ -53,11 +43,6 @@ def step_attestation_provider_provider_list2(test, rg, rg_2, rg_3, checks=None):
checks=checks)


@try_manual
def step_attestation_provider_provider_list2_min(test, rg, rg_2, rg_3, checks=None):
return step_attestation_provider_provider_list2(test, rg, rg_2, rg_3, checks)


# EXAMPLE: /AttestationProviders/patch/AttestationProviders_Update
@try_manual
def step_attestation_provider_update(test, rg, rg_2, rg_3, checks=None):
Expand All @@ -70,16 +55,6 @@ def step_attestation_provider_update(test, rg, rg_2, rg_3, checks=None):
checks=checks)


@try_manual
def step_attestation_provider_update_min(test, rg, rg_2, rg_3, checks=None):
if checks is None:
checks = []
test.cmd('az attestation attestation-provider update '
'--provider-name "myattestationprovider" '
'--resource-group "{rg}"',
checks=checks)


# EXAMPLE: /AttestationProviders/delete/AttestationProviders_Delete
@try_manual
def step_attestation_provider_delete(test, rg, rg_2, rg_3, checks=None):
Expand All @@ -91,11 +66,6 @@ def step_attestation_provider_delete(test, rg, rg_2, rg_3, checks=None):
checks=checks)


@try_manual
def step_attestation_provider_delete_min(test, rg, rg_2, rg_3, checks=None):
return step_attestation_provider_delete(test, rg, rg_2, rg_3, checks)


# EXAMPLE: /Operation/put/AttestationProviders_Create
@try_manual
def step_create_provider(test, rg, rg_2, rg_3, checks=None):
Expand All @@ -107,11 +77,6 @@ def step_create_provider(test, rg, rg_2, rg_3, checks=None):
checks=checks)


@try_manual
def step_create_provider_min(test, rg, rg_2, rg_3, checks=None):
return step_create_provider(test, rg, rg_2, rg_3, checks)


# EXAMPLE: /Operation/get/Operations_List
@try_manual
def step_list_operation(test, rg, rg_2, rg_3, checks=None):
Expand All @@ -120,8 +85,3 @@ def step_list_operation(test, rg, rg_2, rg_3, checks=None):
test.cmd('az attestation list-operation',
checks=checks)


@try_manual
def step_list_operation_min(test, rg, rg_2, rg_3, checks=None):
return step_list_operation(test, rg, rg_2, rg_3, checks)

Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
from .example_steps import step_attestation_provider_provider_list
from .example_steps import step_attestation_provider_provider_list2
from .example_steps import step_attestation_provider_delete
from .example_steps import step_list_operation_min
from .example_steps import step_create_provider_min
from .example_steps import step_attestation_provider_show_min
from .example_steps import step_attestation_provider_provider_list_min
from .example_steps import step_attestation_provider_provider_list2_min
from .example_steps import step_attestation_provider_delete_min
from .. import (
try_manual,
raise_if,
Expand Down Expand Up @@ -67,17 +61,6 @@ def call_scenario(test, rg, rg_2, rg_3):

@try_manual
def call_scenario_min(test, rg, rg_2, rg_3):
setup_scenario(test, rg, rg_2, rg_3)
step_list_operation_min(test, rg, rg_2, rg_3, checks=[])
step_create_provider_min(test, rg, rg_2, rg_3, checks=[])
step_attestation_provider_show_min(test, rg, rg_2, rg_3, checks=[])
mytest(test, rg, rg_2, rg_3)
step_attestation_provider_provider_list_min(test, rg, rg_2, rg_3, checks=[])
step_attestation_provider_provider_list2_min(test, rg, rg_2, rg_3, checks=[])
step_attestation_provider_delete_min(test, rg, rg_2, rg_3, checks=[])
cleanup_scenario(test, rg, rg_2, rg_3)


# Test class for Scenario
@try_manual
class AttestationScenarioTest(ScenarioTest):
Expand All @@ -95,13 +78,3 @@ def test_attestation_Scenario(self, rg, rg_2, rg_3):
calc_coverage(__file__)
raise_if()


@ResourceGroupPreparer(name_prefix='clitestattestation_MyResourceGroup'[:7], key='rg', parameter_name='rg')
@ResourceGroupPreparer(name_prefix='clitestattestation_testrg1'[:7], key='rg_2', parameter_name='rg_2')
@ResourceGroupPreparer(name_prefix='clitestattestation_sample-resource-group'[:7], key='rg_3',
parameter_name='rg_3')
def test_attestation_Scenario_min(self, rg, rg_2, rg_3):
call_scenario_min(self, rg, rg_2, rg_3)
calc_coverage(__file__)
raise_if()

Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,3 @@ def step_virtual_machine_assess_patch(test, rg, checks=None):
'--vm-name "myVMName"',
checks=checks)


@try_manual
def step_virtual_machine_assess_patch_min(test, rg, checks=None):
return step_virtual_machine_assess_patch(test, rg, checks)

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from azure.cli.testsdk import ScenarioTest
from azure.cli.testsdk import ResourceGroupPreparer
from .example_steps import step_virtual_machine_assess_patch
from .example_steps import step_virtual_machine_assess_patch_min
from .. import (
try_manual,
raise_if,
Expand Down Expand Up @@ -45,11 +44,6 @@ def call_scenario(test, rg):

@try_manual
def call_scenario_min(test, rg):
setup_scenario(test, rg)
step_virtual_machine_assess_patch_min(test, rg, checks=[])
cleanup_scenario(test, rg)


# Test class for Scenario
@try_manual
class VmScenarioTest(ScenarioTest):
Expand All @@ -64,10 +58,3 @@ def test_vm_Scenario(self, rg):
calc_coverage(__file__)
raise_if()


@ResourceGroupPreparer(name_prefix='clitestvm_myResourceGroupName'[:7], key='rg', parameter_name='rg')
def test_vm_Scenario_min(self, rg):
call_scenario_min(self, rg)
calc_coverage(__file__)
raise_if()

Loading